Skip to content
DeepForgeby svx
All problems
MediumInformation Theoryinfo-288

Elias Delta Code Length

Problem

Return the length in bits of the Elias delta code for n >= 1. With L = floor(log2(n)) + 1 equal to the bit length of n, the code stores L using a gamma codeword and then the remaining L - 1 bits, for a total of gamma_length(L) + L - 1. Return 0 for n <= 0.

Hint

Delta coding first encodes the length of the number with a gamma code.

Test cases

case 1
in: [1]
expected: 1
case 2
in: [2]
expected: 4
case 3
in: [8]
expected: 8
case 4
in: [100]
expected: 11
case 5
in: [7]
expected: 5
Starter codePython
def elias_delta_length(n):
    # Your code here
    pass

5 test cases · run your code against them in the editor