Difference between revisions of "Aufgaben:Exercise 2.3: About the LZ78 Compression"

From LNTwww
(Die Seite wurde neu angelegt: „ {{quiz-Header|Buchseite=Informationstheorie und Quellencodierung/Komprimierung nach Lempel, Ziv und Welch }} right| :Im Geg…“)
 
 
(33 intermediate revisions by 5 users not shown)
Line 1: Line 1:
  
{{quiz-Header|Buchseite=Informationstheorie und Quellencodierung/Komprimierung nach Lempel, Ziv und Welch
+
{{quiz-Header|Buchseite=Information_Theory/Compression_According_to_Lempel,_Ziv_and_Welch
 
}}
 
}}
  
[[File:P_ID2434__Inf_A_2_3.png|right|]]
+
[[File:P_ID2434__Inf_A_2_3.png|right|frame|The LZ78–inventors]]
:Im Gegensatz zur Entropiecodierung nach Huffman oder nach Shannon, bei der man die Quellenstatistik (möglichst genau) kennen muss, sind solche Einschränkungen bei den von Abraham Lempel und Jacob Ziv entwickelten Komprimierungsverfahren nicht gegeben. Man spricht von universeller Quellencodierung.
+
In contrast to  "Entropy Coding"  according to Huffman or Shannon, where one must know the source statistics  (as precisely as possible),  such restrictions do not apply to the compression methods developed by  [https://en.wikipedia.org/wiki/Abraham_Lempel Abraham Lempel]  and  [https://en.wikipedia.org/wiki/Jacob_Ziv Jacob Ziv] .  This is called  "Universal Source Coding".
  
:Wir betrachten in dieser Aufgabe die 1978 erstmals veröffentlichte Variante LZ78 Codiert werden soll der String &nbsp;<b>BARBARA&ndash;BAR</b>.
+
In this exercise, we consider the variant first published in 1978&nbsp; [LZ78].&nbsp;  The string &nbsp;<b>BARBARA&ndash;BAR</b> is to be encoded.
 +
*The procedure&nbsp; "LZ78"&nbsp; works with a global dictionary, which is initially only filled with an empty character&nbsp; $(\varepsilon)$&nbsp; under the index&nbsp; $I = 0$.&nbsp; This distinguishes&nbsp; "LZ78"&nbsp; from its predecessor&nbsp; "LZ77"&nbsp; (with local dictionary)&nbsp; and also from its successor&nbsp; "LZW"&nbsp; (dictionary is prefilled with the possible characters).
 +
*If a character or a word fragment&nbsp; (several characters)&nbsp; of the input string is found in the dictionary, the index&nbsp; $I_0$&nbsp; of this entry is output together with the next input character&nbsp; $Z$&nbsp;.&nbsp; In each step&nbsp; $i$&nbsp; the output is therefore: &nbsp;  $(I_0, \ Z)$.
 +
*Afterwards, the new string is entered into the dictionary under the next free index&nbsp; $I_{\rm new}$.
 +
*If one considers the dictionary as a field&nbsp; $W\big[\hspace{0.05cm}I\hspace{0.05cm}\big]$&nbsp; with&nbsp; $I &ge; 0$, where each element contains a string of arbitrary length, then with the character variable&nbsp; $Z$:
 +
:$$W \big[\hspace{0.05cm}I_{\rm new}\hspace{0.05cm}\big]  = W\big[\hspace{0.05cm}I_0\hspace{0.05cm}\big] + Z \hspace{0.05cm}. $$
  
: <ul class="liste_ohne"><li>LZ78 arbeitet mit einem globalen Wörterbuch, das zu Beginn nur mit einem leeren Zeichen (<b>&epsilon;</b>) unter dem Index <i>I</i> = 0 gefüllt ist. Dadurch unterscheidet sich LZ78 von seinem Vorgänger LZ77 (lokales Wörterbuch) und auch von seinem Nachfolger LZW (Wörterbuch ist mit den möglichen Zeichen vorbelegt).
 
  
: <ul class="liste_ohne"><li>Wird ein Zeichen oder ein Wortfragment (mehrere Zeichen) des Eingabestrings im Wörterbuch gefunden, so wird der Index <i>I</i><sub>0</sub> dieses Eintrags zusammen mit dem nächsten Eingangszeichen <i>Z</i> ausgegeben. In jedem Schritt <i>i</i> lautet also die Ausgabe: (<i>I</i><sub>0</sub>, <i>Z</i>).
+
For clarification, a simple example:
 +
*At a given time, the dictionary is filled up to index&nbsp; $I_{\rm act }= 20$.
 +
*'''Handy'''&nbsp; is waiting to be encoded.&nbsp; In the dictionary, &nbsp; "<b>Ha</b>"&nbsp; is found under index&nbsp; $I = 11$&nbsp; and the entry&nbsp; "<b>Han</b>"&nbsp; under index&nbsp; $I = 16$.
 +
*Thus, the current code output is &nbsp;  $(I_0,  Z) = (16,$ <b>d</b>$)$&nbsp; and the following is entered into the dictionary as a new phrase:
 +
 +
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $W(21) = $ <b>Hand</b>.
 +
*Now the string&nbsp; <b>y</b>&nbsp; is available for coding.&nbsp; If no suitable entry is found, &nbsp; $(0,$ <b>y</b>$)$&nbsp; is output and a new entry is made in the dictionary:  
 +
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $W(22) =  \rm &epsilon;$&nbsp; +  <b>y</b> $=$ <b>y</b> .
  
: <ul class="liste_ohne"><li>Anschließend wird der neue String unter dem nächsten freien Index <i>I</i><sub>neu</sub> ins Wörterbuch eingetragen. Betrachtet man das Wörterbuch als ein Feld <i>W</i>[<i>I</i>] mit <i>I</i> &#8805; 0, bei dem ein jedes Element eine Zeichenkette beliebiger Länge enthält, so gilt mit der Character&ndash;Variablen <i>Z</i>:
+
For subtask&nbsp; '''(6)'''&nbsp; you can assume the following:
:$$W (I_{\rm neu})  = W(I_0) + Z \hspace{0.05cm}. $$
+
* The decimal number&nbsp; $I$&nbsp; (index) is represented in binary by three bits.
 +
* The character&nbsp; $Z &#8712; \{$<b>A</b>,&nbsp; <b>B</b>,&nbsp; <b>R</b>,&nbsp; <b>&ndash;</b>$ \}$&nbsp; is binary coded by two bits each.
  
:Zur Verdeutlichung ein einfaches Beispiel:
 
  
: <ul class="liste_ohne"><li>Zu einem gegebenen Zeitpunkt ist das Wörterbuch bis zum Index <i>I</i><sub>akt</sub> = 20 gefüllt.
 
  
: <ul class="liste_ohne"><li>Zur Codierung steht Handy an. Im Wörterbuch findet man unter dem Index <i>I</i> = 11 den Eintrag <b>Ha</b> und unter dem Index <i>I</i> = 16 den Eintrag <b>Han</b>.
 
  
: <ul class="liste_ohne"><li> Somit lautet die aktuelle Coderausgabe (<i>I</i><sub>0</sub>, <i>Z</i>) = (16, <b>d</b>) und ins Wörterbuch wird als neue Phrase eingetragen: <i>W</i>(21) = <b>Hand</b>.
 
  
: <ul class="liste_ohne"><li>Nun liegt der String <b>y</b> zur Codierung an. Findet man hierfür keinen passenden Eintrag, so wird <nobr>(0, <b>y</b>)</nobr> ausgegeben und <i>W</i>(22) = <b>&epsilon;</b> +  <b>y</b> = <b>y</b> neu ins Wörterbuch eingetragen.
 
  
:Für die Teilaufgabe 6) können Sie von folgenden Voraussetzungen ausgehen:
+
Hints:
 +
*The exercise belongs to the chapter&nbsp; [[Information_Theory/Komprimierung_nach_Lempel,_Ziv_und_Welch|Compression According to Lempel, Ziv and Welch]].
 +
*In particular, reference is made to the page&nbsp; [[Information_Theory/Komprimierung_nach_Lempel,_Ziv_und_Welch#The_Lempel-Ziv_variant_LZ78|The Lempel-Ziv Variant LZ78]].
 +
*The original literature&nbsp; [LZ78]&nbsp; on this method is: <br> &nbsp; &nbsp; Ziv, J.; Lempel, A.:&nbsp; Compression of Individual Sequences via Variable-Rate Coding.&nbsp; In: IEEE Transactions on Information Theory, no. 5, vol. 24, 1978, p. 530–536.
 +
 +
*[[Aufgaben:2.3Z_Zur_LZ77-Codierung|Exercise 2.3Z]]&nbsp; and&nbsp; [[Aufgaben:Aufgabe_2.4:_Zum_LZW-Algorithmus|Exercise 2.4]]&nbsp; deal with other Lempel&ndash;Ziv methods in a similar way.
  
:* Die Dezimalzahl <i>I</i> (Index) wird durch 3 Bit binär dargestellt.
 
  
:* Das Zeichen <i>Z</i> &#8712; {<b>A</b>, <b>B</b>, <b>R</b>, <b>&ndash;</b>} wird mit jeweils 2 Bit binärcodiert.
+
===Questions===
 
 
:<b>Hinweis:</b> Die Aufgabe bezieht sich auf das Kapitel 2.2. Ähnliche Aufgaben zu anderen LZ&ndash;Methoden finden Sie unter folgenden Links:
 
 
 
:* Aufgabe Z2.3: LZ77-Codierung von <b>BARBARA&ndash;BAR,</b>
 
 
 
:* Aufgabe A2.4: LZW&ndash;(De&ndash;)Codierung einer binären Eingangsfolge.
 
 
 
 
 
===Fragebogen===
 
  
 
<quiz display=simple>
 
<quiz display=simple>
{Welche Aussagen gelten für die Vorbelegung des LZ78&ndash;Wörterbuches?
+
{Which statements apply to the preassignment of the LZ78 dictionary?
|type="[]"}
+
|type="()"}
+ Vorbelegt ist nur der Index <i>I</i> = 0 mit dem Leerzeichen (<i>&epsilon;</i>).
+
+ Only the index&nbsp; $I = 0$&nbsp; with the space&nbsp; $(\varepsilon)$ is preassigned.
- Vorbelegt sind die Indizes <i>I</i> = 0 bis <i>I</i> = 3 mit den vier Zeichen.
+
- The indices&nbsp; $I = 0$&nbsp; to&nbsp; $I = 3$&nbsp; with the four characters&nbsp; "'''A'''",&nbsp; "'''B'''",&nbsp; '''R'''&nbsp; and&nbsp; "'''&ndash;'''" are preallocated.
  
  
{Was geschieht im Codierschritt <i>i</i> = 1?
+
{What happens in the coding step&nbsp; $i = 1$?
 
|type="[]"}
 
|type="[]"}
+ Die Coderausgabe lautet (0, <b>B</b>).
+
+ The coder output is: &nbsp; $(0,$ <b>B</b>$)$.
+ Der Wörterbucheintrag lautet: <i>W</i>(<i>I</i> = 1) = <b>B</b>.
+
+ The dictionary entry is: &nbsp; $W(I = 1) =$ <b>B</b>.
- Der Wörterbucheintrag lautet: <i>W</i>(<i>I</i> = 1) = <b>BA</b>.
+
- The dictionary entry is: &nbsp; $W(I = 1) =$ <b>BA</b>.
  
  
{Welche Aussagen gelten für die Codierschritte <i>i</i> = 2 und <i>i</i> = 3?
+
{Which statements are true for the coding steps&nbsp; $i = 2$&nbsp; and&nbsp; $i = 3$?
 
|type="[]"}
 
|type="[]"}
+ Für <i>i</i> = 2 gilt: Ausgabe (0, <b>A</b>), Eintrag <i>W</i>(<i>I</i> = 2) = <b>A</b>.
+
+ For&nbsp; $i = 2$&nbsp;, the following is true: &nbsp; Output&nbsp; $(0,$ <b>A</b>$)$, &nbsp; entry&nbsp; $W(I = 2) =<b>A</b>.
+ Für <i>i</i> = 3 gilt: Ausgabe (0, <b>R</b>), Eintrag <i>W</i>(<i>I</i> = 3) = <b>R</b>.
+
+ For&nbsp; $i = 3$&nbsp;, the following is true: &nbsp; Output&nbsp; $(0,$ <b>R</b>$)$, &nbsp; entry&nbsp; $W(I = 3) =$ <b>R</b>.
  
  
{Welche Aussagen gelten für den Codierschritt <i>i</i> = 4?
+
{Which statements are true for the coding step&nbsp; $i = 4$?
 
|type="[]"}
 
|type="[]"}
- Bei Schritt <i>i</i> = 4 wird <b>BAR</b> gemeinsam codiert.
+
- At step&nbsp; $i = 4$&nbsp; &nbsp; <b>BAR</b>&nbsp; is coded together.
+ Bei Schritt <i>i</i> = 4 wird <b>BA</b> gemeinsam codiert.
+
+ At step&nbsp; $i = 4$&nbsp; &nbsp; <b>BA</b>&nbsp; is coded together.
- Die Coderausgabe lautet (2, <b>AR</b>).
+
- The coder output is: &nbsp; $(2,$ <b>AR</b>$)$.
+ Die Coderausgabe lautet (1, <b>A</b>).
+
+ The coder output is: &nbsp; $(1,$ <b>A</b>$)$.
  
  
{Vervollständigen Sie die LZ78&ndash;Codierung. Nach welchem Codierschritt <i>i</i> ist <b>BARBARA&ndash;BAR</b> vollständig codiert?
+
{Complete the LZ78 coding.&nbsp; After which coding step&nbsp; $i_{\rm end}$&nbsp; is&nbsp; "<b>BARBARA&ndash;BAR</b>"&nbsp; completely coded?
 
|type="{}"}
 
|type="{}"}
$i$ = { 7 3% }
+
$i_{\rm end} \ = \ $ { 7 3% }
  
  
{Wieviele Binärzeichen benötigt man, um  <b>BARBARA&ndash;BAR</b> zu codieren? Beachten Sie die Hinweise auf der Angabenseite.
+
{How many binary characters are needed to code&nbsp; "<b>BARBARA&ndash;BAR"</b>&nbsp;?&nbsp; Follow the instructions on the information page.
 
|type="{}"}
 
|type="{}"}
$ohne\ Codierung:\ N$ = { 22 3% } $bit$
+
$\text{without coding: }\ N \ = \ $ { 22 3% } $\ \rm bits$
$mit\ LZ78-Codierung:\ N$ = { 35 3% } $bit$
+
$\text{with LZ78 coding: }\ N \ = \ $ { 35 3% } $\ \rm bits$
  
  
Line 82: Line 84:
 
</quiz>
 
</quiz>
  
===Musterlösung===
+
===Solution===
 
{{ML-Kopf}}
 
{{ML-Kopf}}
:<b>1.</b>&nbsp;&nbsp;Zutreffend für den LZ78&ndash;Algorithmus ist <u>Aussage 1</u>. Die Vorbelegung gemäß Aussage 2 gilt dagegen für den LZW&ndash;Algorithmus, der 1983 gemeinsam mit Terry Welch veröffentlicht wurde.
+
'''(1)'''&nbsp; <u>Statement 1</u> applies to the LZ78 algorithm:
 +
*In contrast, the preassignment according to statement 2 is true for the LZW algorithm, which was published in 1983 together with Terry Welch.
 +
 
  
:<b>2.</b>&nbsp;&nbsp;<b>&epsilon;</b> bezeichnet das leere Zeichen. Da <b>&epsilon;</b> + <b>B</b> = <b>B</b> ergibt, sind die <u>Aussagen 1 und 2</u> richtig. Dagegen würde die Aussage 3 wieder für die LZW&ndash;Komprimierung zutreffen.
 
  
:<b>3.</b>&nbsp;&nbsp;<u>Beide Aussagen</u> treffen zu.
 
  
:<b>4.</b>&nbsp;&nbsp;Im Wörterbuch wird unter dem Index <i>I</i> = 1 das Zeichen <b>B</b> gefunden und das nächste Zeichen <b>A</b> der Eingangsfolge wird angehängt: (1, <b>A</b>). Richtig sind somit die <u>Aussagen 2 und 4</u>. Die Aussage 3 kann schon deshalb nicht stimmen, da <i>Z</i> nur ein Zeichen sein kann und keine Zeichenfolge.
+
'''(2)'''&nbsp; $\rm &epsilon;$&nbsp; denotes the empty character.&nbsp;  
 +
*Since&nbsp; $\rm &epsilon;$ + <b>B</b> = <b>B</b> &nbsp; &rArr; &nbsp; <u>statements 1 and 2</u> are correct.  
 +
*Statement 3 is again only true for LZW compression.
  
:<b>5.</b>&nbsp;&nbsp;Der gesamte Codiervorgang ist in einer Tabelle zusammengefasst:
 
[[File:P_ID2435__Inf_A_2_3f.png|center|]]
 
:Man erkennt:
 
  
:* Zu jedem Zeitpunkt <i>i</i> wird die bearbeitete Zeichenfolge in das Wörterbuch eingetragen.
 
  
:* Zum Zeitpunkt <u><i>i</i> = 7</u> ist der Codiervorgang abgeschlossen.
+
'''(3)'''&nbsp; Here <u>both statements</u> are true.
  
:<b>6.</b>&nbsp;&nbsp; Stellt man alle Indizes mit 3 Bit dar und die vier Zeichen (Character) mit je 2 Bit, so kommt man zu folgenden Ergebnissen:
 
  
:* ohne Codierung: <i>N</i> = 11 &middot; 2 = <u>22 Bit</u>,
 
  
:* mit LZ78&ndash;Codierung: <i>N</i> = 7 &middot; (3 + 2) = <u>35 Bit</u>.
+
'''(4)'''&nbsp; <u>Statements 2 and 4</u> are correct:
 +
*In the dictionary, character&nbsp; <b>B</b>&nbsp; is found under index &nbsp; $I = 1$.
 +
*The next character&nbsp; <b>A</b>&nbsp; of the input sequence is appended: &nbsp; <b>(1, A)</b>.
 +
*Statement 3 cannot be correct because&nbsp; $Z$&nbsp; can only be a character and not a character sequence.
  
:Daran erkennt man:
 
  
:* Eine jede LZ&ndash;Komprimierung macht erst bei einer größeren Datei Sinn, auch dann, wenn man glaubt, dass ein Text wie <b>BARBARA&ndash;BAR</b> dem LZ78&ndash;Algorithmus entgegenkommt.
 
  
:* Mit variabler Bitanzahl für den Index entsprechend der Theorieseite 5 und Aufgabe A2.4 ergibt sich für dieses LZ78-Beispiel
+
[[File:EN_Inf_A_2_3f.png|right|frame|LZ78 coding of&nbsp; "<b>BARBARA–BAR</b>"]]
:$$N = 1 \cdot 3 + 2 \cdot 4 + 4 \cdot 5 = 31 \,{\rm Bit}\hspace{0.05cm}.$$
+
'''(5)'''&nbsp; The entire coding process is summarised in the table on the right.&nbsp; One can see:
 +
* At each time&nbsp; $i$,&nbsp; the edited string is entered into the dictionary.
 +
* At time&nbsp; $\underline{i=7}$&nbsp; the coding process is completed.
 +
 
 +
 
 +
 
 +
'''(6)'''&nbsp; If we represent all indices with three bits and the four characters with two bits each, we get the following results:
 +
* Without coding: &nbsp; $N = 11 \cdot 2 \hspace{0.15cm}\underline {= 22 \, \rm bits}$,
 +
* with LZ78 coding: &nbsp; $N = 7 \cdot (3+2) \hspace{0.15cm}\underline {= 35 \, \rm bits}$.
 +
 
 +
 
 +
You can see from this:
 +
* Any LZ compression only makes sense with a larger file, even if one believes that a text like&nbsp; "<b>BARBARA&ndash;BAR</b>"&nbsp; accommodates the LZ78 algorithm.
 +
* With variable number of bits for the index according to Exercise 2.4, the result for this LZ78 example would be:
 +
:$$N = 1 \cdot 3 + 2 \cdot 4 + 4 \cdot 5 = 31 \,{\rm bits}\hspace{0.05cm}.$$
 
{{ML-Fuß}}
 
{{ML-Fuß}}
  
  
  
[[Category:Aufgaben zu Informationstheorie und Quellencodierung|^2.2 Komprimierung nach Lempel, Ziv und Welch^]]
+
 
 +
 
 +
 
 +
[[Category:Information Theory: Exercises|^2.2 Lempel-Ziv-Welch Compression^]]

Latest revision as of 14:10, 10 August 2021

The LZ78–inventors

In contrast to  "Entropy Coding"  according to Huffman or Shannon, where one must know the source statistics  (as precisely as possible),  such restrictions do not apply to the compression methods developed by  Abraham Lempel  and  Jacob Ziv .  This is called  "Universal Source Coding".

In this exercise, we consider the variant first published in 1978  [LZ78].  The string  BARBARA–BAR is to be encoded.

  • The procedure  "LZ78"  works with a global dictionary, which is initially only filled with an empty character  $(\varepsilon)$  under the index  $I = 0$.  This distinguishes  "LZ78"  from its predecessor  "LZ77"  (with local dictionary)  and also from its successor  "LZW"  (dictionary is prefilled with the possible characters).
  • If a character or a word fragment  (several characters)  of the input string is found in the dictionary, the index  $I_0$  of this entry is output together with the next input character  $Z$ .  In each step  $i$  the output is therefore:   $(I_0, \ Z)$.
  • Afterwards, the new string is entered into the dictionary under the next free index  $I_{\rm new}$.
  • If one considers the dictionary as a field  $W\big[\hspace{0.05cm}I\hspace{0.05cm}\big]$  with  $I ≥ 0$, where each element contains a string of arbitrary length, then with the character variable  $Z$:
$$W \big[\hspace{0.05cm}I_{\rm new}\hspace{0.05cm}\big] = W\big[\hspace{0.05cm}I_0\hspace{0.05cm}\big] + Z \hspace{0.05cm}. $$


For clarification, a simple example:

  • At a given time, the dictionary is filled up to index  $I_{\rm act }= 20$.
  • Handy  is waiting to be encoded.  In the dictionary,   "Ha"  is found under index  $I = 11$  and the entry  "Han"  under index  $I = 16$.
  • Thus, the current code output is   $(I_0, Z) = (16,$ d$)$  and the following is entered into the dictionary as a new phrase:

            $W(21) = $ Hand.

  • Now the string  y  is available for coding.  If no suitable entry is found,   $(0,$ y$)$  is output and a new entry is made in the dictionary:

            $W(22) = \rm ε$  + y $=$ y .

For subtask  (6)  you can assume the following:

  • The decimal number  $I$  (index) is represented in binary by three bits.
  • The character  $Z ∈ \{$ABR$ \}$  is binary coded by two bits each.




Hints:

  • The exercise belongs to the chapter  Compression According to Lempel, Ziv and Welch.
  • In particular, reference is made to the page  The Lempel-Ziv Variant LZ78.
  • The original literature  [LZ78]  on this method is:
        Ziv, J.; Lempel, A.:  Compression of Individual Sequences via Variable-Rate Coding.  In: IEEE Transactions on Information Theory, no. 5, vol. 24, 1978, p. 530–536.


Questions

1

Which statements apply to the preassignment of the LZ78 dictionary?

Only the index  $I = 0$  with the space  $(\varepsilon)$ is preassigned.
The indices  $I = 0$  to  $I = 3$  with the four characters  "A",  "B",  R  and  "" are preallocated.

2

What happens in the coding step  $i = 1$?

The coder output is:   $(0,$ B$)$.
The dictionary entry is:   $W(I = 1) =$ B.
The dictionary entry is:   $W(I = 1) =$ BA.

3

Which statements are true for the coding steps  $i = 2$  and  $i = 3$?

For  $i = 2$ , the following is true:   Output  $(0,$ A$)$,   entry  $W(I = 2) =$ A.
For  $i = 3$ , the following is true:   Output  $(0,$ R$)$,   entry  $W(I = 3) =$ R.

4

Which statements are true for the coding step  $i = 4$?

At step  $i = 4$    BAR  is coded together.
At step  $i = 4$    BA  is coded together.
The coder output is:   $(2,$ AR$)$.
The coder output is:   $(1,$ A$)$.

5

Complete the LZ78 coding.  After which coding step  $i_{\rm end}$  is  "BARBARA–BAR"  completely coded?

$i_{\rm end} \ = \ $

6

How many binary characters are needed to code  "BARBARA–BAR" ?  Follow the instructions on the information page.

$\text{without coding: }\ N \ = \ $

$\ \rm bits$
$\text{with LZ78 coding: }\ N \ = \ $

$\ \rm bits$


Solution

(1)  Statement 1 applies to the LZ78 algorithm:

  • In contrast, the preassignment according to statement 2 is true for the LZW algorithm, which was published in 1983 together with Terry Welch.



(2)  $\rm ε$  denotes the empty character. 

  • Since  $\rm ε$ + B = B   ⇒   statements 1 and 2 are correct.
  • Statement 3 is again only true for LZW compression.


(3)  Here both statements are true.


(4)  Statements 2 and 4 are correct:

  • In the dictionary, character  B  is found under index   $I = 1$.
  • The next character  A  of the input sequence is appended:   (1, A).
  • Statement 3 cannot be correct because  $Z$  can only be a character and not a character sequence.


LZ78 coding of  "BARBARA–BAR"

(5)  The entire coding process is summarised in the table on the right.  One can see:

  • At each time  $i$,  the edited string is entered into the dictionary.
  • At time  $\underline{i=7}$  the coding process is completed.


(6)  If we represent all indices with three bits and the four characters with two bits each, we get the following results:

  • Without coding:   $N = 11 \cdot 2 \hspace{0.15cm}\underline {= 22 \, \rm bits}$,
  • with LZ78 coding:   $N = 7 \cdot (3+2) \hspace{0.15cm}\underline {= 35 \, \rm bits}$.


You can see from this:

  • Any LZ compression only makes sense with a larger file, even if one believes that a text like  "BARBARA–BAR"  accommodates the LZ78 algorithm.
  • With variable number of bits for the index according to Exercise 2.4, the result for this LZ78 example would be:
$$N = 1 \cdot 3 + 2 \cdot 4 + 4 \cdot 5 = 31 \,{\rm bits}\hspace{0.05cm}.$$