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 , the remainder uses exactly bits and the code length is bits.
Properties#
- Prefix-free: the unary part ends at its first
1, which fixes the number of remaining bits. - Tunable by : a larger shortens the unary part but lengthens the remainder. A good 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 write with Golomb modulus , then in binary without its leading 1. With the length is (unary quotient, 2-bit remainder, binary tail) (DBIS Exam WS1617 (not published), Task 2).
Example#
(): gap has , , code 01 001 (5 bits); gap has , , code 1 001 (4 bits). The sequence has gaps , hence 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 : , Golomb(, ) 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.