LZ78

Juan Francisco Rodríguez Herrera
Vicente González Ruiz

July 10, 2017

Contents

1 Fundamentals
2 Encoder
3 Decoder

1 Fundamentals

2 Encoder

  1. w ← 0.
  2. While the input is not exhausted:
    1. k ← next input symbol.
    2. If wk is found in the dictionary, then:
      1. w ← address of wk in the dictionary.
    3. Else:
      1. Output wk.
      2. Insert wk in the dictionary.
      3. w ← 0.

Compression and dictionary examples:

InputOutputComment



a 0a D[1] ←a
b 0b D[2] ←b
a D[1] = a
b 1b D[3] ←ab
c 0c D[4] ←c
b D[2] = b
a 2a D[5] ←ba
b D[2] = b
a D[5] = ba
b 5b D[6] ←bab
a D[1] ←a
a 1a D[7] ←aa
a D[1] ←a
a D[7] ←aa
a 7a D[8] ←aaa
a D[1] = a
a D[7] = aa
a D[8] = aaa
a 8a D[9] ←aaaa
  1. w ← 0.
  2. While the input is not exhausted:
    1. k ← next input symbol.
    2. If wk is found in the dictionary, then:
      1. w ← address of wk in the dictionary.
    3. Else:
      1. Output wk.
      2. Insert wk in the dictionary.
      3. w ← 0.
AddresswkString




1 0 a a
2 0 b b
3 1 b ab
4 0 c c
5 2 a ba
6 5 b bab
7 1 a aa
8 7 a aaa
9 8 a aaaa

3 Decoder

  1. While the input is not exhausted:
    1. Input wk.
    2. Output string(w).
    3. Output k.
    4. Insert wk in the dictionary.

Decoding and dictionary examples:

InputOutputComment



0a a D[1] ←a
0b b D[2] ←b
1b ab D[3] ←ab
0c c D[4] ←c
2a ba D[5] ←ba
5b bab D[6] ←bab
1a aa D[7] ←aa
7a aaa D[8] ←aaa
8a aaaa D[9] ←aaaa
AddresswkString




1 0 a a
2 0 b b
3 1 b ab
4 0 c c
5 2 a ba
6 5 b bab
7 1 a aa
8 7 a aaa
9 8 a aaaa
  1. While the input is not exhausted:
    1. Input wk.
    2. Output string(w).
    3. Output k.
    4. Insert wk in the dictionary.

References

[1]   J. Ziv and A. Lempel. Compression of Individual Sequences via Variable-Rate Coding. IEEE Trans. on Inf. Theory, 24(5):530–536, 1978.