Study Vault Search notes, aliases and full text
Graph
ConceptDBISAI-written · not yet proofread

Golomb Code

Golomb encoding with modulus M writes a non-negative integer x as its quotient ⌊x/M⌋ in unary followed by its remainder x mod M in (truncated) binary.

Know these firstUnary Code

Formula#

If M=2kM = 2^k, the remainder uses exactly kk bits and the code length is q+1+kq + 1 + k bits.

Properties#

  • Prefix-free: the unary part ends at its first 1, which fixes the number of remaining bits.
  • Tunable by MM: a larger MM shortens the unary part but lengthens the remainder. A good MM matches the typical size of the numbers, which is why Golomb codes suit gaps of inverted lists.
  • Building block of the WS 16/17 custom code: for x≥1x \geq 1 write ⌊log⁡2x⌋\lfloor \log_2 x \rfloor with Golomb modulus M=4M = 4, then xx in binary without its leading 1. With ℓ=⌊log⁡2x⌋\ell = \lfloor \log_2 x \rfloor the length is ⌊ℓ/4⌋+1+2+ℓ\lfloor \ell / 4 \rfloor + 1 + 2 + \ell (unary quotient, 2-bit remainder, binary tail) (DBIS Exam WS1617 (not published), Task 2).

Example#

M=8M = 8 (k=3k = 3): gap 99 has q=1q = 1, r=1r = 1, code 01 001 (5 bits); gap 11 has q=0q = 0, r=1r = 1, code 1 001 (4 bits). The sequence 1,10,11,20,21,30,31,401, 10, 11, 20, 21, 30, 31, 40 has gaps 1,9,1,9,1,9,1,91, 9, 1, 9, 1, 9, 1, 9, hence 4⋅4+4⋅5=364 \cdot 4 + 4 \cdot 5 = 36 bits (DBIS Exam WS1314 (not published), Task 1.1; computed here with the convention above, the official solution is not in the exam note).

WS 16/17 code for x=10x = 10: ℓ=3\ell = 3, Golomb(33, M=4M = 4) == 1 11, tail 010: 111010.

Sources#

  • DBIS Exam WS1314 (not published) Task 1, DBIS Exam WS1617 (not published) Task 2
  • Not lectured in WS 25/26.

Search

Type In
↑ ↓ move ↵ open ⇥ next section Ctrl↵ results page Prefix # to search text only