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

From LNTwww
 
(16 intermediate revisions by 3 users not shown)
Line 1: Line 1:
  
{{quiz-Header|Buchseite=Informationstheorie/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|frame|Die LZ78–Erfinder]]
+
[[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  [https://de.wikipedia.org/wiki/Abraham_Lempel Abraham Lempel]  und  [https://de.wikipedia.org/wiki/Jacob_Ziv 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&nbsp; [LZ78].&nbsp;  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.
*Das Verfahren LZ78 arbeitet mit einem globalen Wörterbuch, das zu Beginn nur mit einem leeren Zeichen&nbsp; $(\varepsilon)$&nbsp; unter dem Index&nbsp; $I = 0$&nbsp; gefüllt ist.&nbsp; Dadurch unterscheidet sich &bdquo;LZ78&rdquo; von seinem Vorgänger &bdquo;LZ77&rdquo; (mit lokalem Wörterbuch) und auch von seinem Nachfolger &bdquo;LZW&rdquo; (Wörterbuch ist mit den möglichen Zeichen vorbelegt).
+
*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).
*Wird ein Zeichen oder ein Wortfragment (mehrere Zeichen) des Eingabestrings im Wörterbuch gefunden, so wird der Index&nbsp; $I_0$&nbsp; dieses Eintrags zusammen mit dem nächsten Eingangszeichen&nbsp; $Z$&nbsp; ausgegeben.&nbsp; In jedem Schritt&nbsp; $i$&nbsp; lautet also die Ausgabe: &nbsp;  $(I_0, \ Z)$.
+
*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)$.
*Anschließend wird der neue String unter dem nächsten freien Index&nbsp; $I_{\rm neu}$&nbsp; ins Wörterbuch eingetragen.  
+
*Afterwards, the new string is entered into the dictionary under the next free index&nbsp; $I_{\rm new}$.  
*Betrachtet man das Wörterbuch als ein Feld&nbsp; $W\big[\hspace{0.05cm}I\hspace{0.05cm}\big]$&nbsp; mit&nbsp; $I &ge; 0$, bei dem ein jedes Element eine Zeichenkette beliebiger Länge enthält, so gilt mit der Character&ndash;Variablen&nbsp; $Z$:
+
*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 neu}\hspace{0.05cm}\big]  = W\big[\hspace{0.05cm}I_0\hspace{0.05cm}\big] + Z \hspace{0.05cm}. $$
+
:$$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}. $$
  
Zur Verdeutlichung ein einfaches Beispiel:
 
*Zu einem gegebenen Zeitpunkt ist das Wörterbuch bis zum Index&nbsp; $I_{\rm akt }= 20$&nbsp; gefüllt.
 
*Zur Codierung steht&nbsp; '''Handy'''&nbsp; an.&nbsp; Im Wörterbuch findet man unter dem Index&nbsp; $I = 11$&nbsp; den Eintrag&nbsp; <b>Ha</b>&nbsp; und unter dem Index&nbsp; $I = 16$&nbsp; den Eintrag <b>Han</b>.
 
*Somit lautet die aktuelle Coderausgabe &nbsp;  $(I_0,  Z) = (16,$ <b>d</b>$)$&nbsp; und ins Wörterbuch wird als neue Phrase eingetragen: &nbsp; $W(21) =$ <b>Hand</b>.
 
*Nun liegt der String&nbsp; <b>y</b>&nbsp; zur Codierung an.&nbsp; Findet man hierfür keinen passenden Eintrag, so wird&nbsp; $(0,$ <b>y</b>$)$&nbsp; ausgegeben und ins Wörterbuch wird neu eingetragen: &nbsp; $W(22) = $ ''&epsilon;'' +  <b>y</b> $=$ <b>y</b> .
 
  
 +
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> .
  
Für die Teilaufgabe&nbsp; '''(6)'''&nbsp; können Sie von folgenden Voraussetzungen ausgehen:
+
For subtask&nbsp; '''(6)'''&nbsp; you can assume the following:
* Die Dezimalzahl&nbsp; $I$&nbsp; (Index) wird durch drei Bit binär dargestellt.
+
* The decimal number&nbsp; $I$&nbsp; (index) is represented in binary by three bits.
* Das Zeichen&nbsp; $Z &#8712; \{$<b>A</b>,&nbsp; <b>B</b>,&nbsp; <b>R</b>,&nbsp; <b>&ndash;</b>$ \}$&nbsp; wird mit jeweils zwei Bit binär codiert.
+
* 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.
  
  
Line 29: Line 32:
  
  
 
+
Hints:
''Hinweise:''
+
*The exercise belongs to the chapter&nbsp; [[Information_Theory/Komprimierung_nach_Lempel,_Ziv_und_Welch|Compression According to Lempel, Ziv and Welch]].
*Die Aufgabe gehört zum  Kapitel&nbsp; [[Informationstheorie/Komprimierung_nach_Lempel,_Ziv_und_Welch|Komprimierung nach Lempel, Ziv und 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]].
*Insbesondere wird auf die Seite&nbsp; [[Informationstheorie/Komprimierung_nach_Lempel,_Ziv_und_Welch#Die_Lempel.E2.80.93Ziv.E2.80.93Variante_LZ78|Die Lempel-Ziv-Variante LZ78]]&nbsp; Bezug genommen.
+
*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.
*Die Originalliteratur&nbsp; [LZ78]&nbsp; zu diesem Verfahren lautet: &nbsp; <br>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.
 
 
   
 
   
*Die&nbsp; [[Aufgaben:2.3Z_Zur_LZ77-Codierung|Aufgabe 2.3Z]]&nbsp; sowie die&nbsp; [[Aufgaben:2.4_LZW-Algorithmus|Aufgabe 2.4]]&nbsp; behandeln andere Lempel&ndash;Ziv-Verfahren in ähnlicher Weise.
+
*[[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.
  
  
===Fragebogen===
+
===Questions===
  
 
<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&nbsp; $I = 0$&nbsp; mit dem Leerzeichen&nbsp; $(\varepsilon)$.
+
+ Only the index&nbsp; $I = 0$&nbsp; with the space&nbsp; $(\varepsilon)$ is preassigned.
- Vorbelegt sind die Indizes&nbsp; $I = 0$&nbsp; bis&nbsp; $I = 3$&nbsp; mit den vier Zeichen&nbsp; '''A''',&nbsp; '''B''',&nbsp; '''R'''&nbsp; und&nbsp; '''&ndash;''' .
+
- 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&nbsp; $i = 1$?
+
{What happens in the coding step&nbsp; $i = 1$?
 
|type="[]"}
 
|type="[]"}
+ Die Coderausgabe lautet: &nbsp; $(0,$ <b>B</b>$)$.
+
+ The coder output is: &nbsp; $(0,$ <b>B</b>$)$.
+ Der Wörterbucheintrag lautet: &nbsp; $W(I = 1) =$ <b>B</b>.
+
+ The dictionary entry is: &nbsp; $W(I = 1) =$ <b>B</b>.
- Der Wörterbucheintrag lautet: &nbsp; $W(I = 1) =$ <b>BA</b>.
+
- The dictionary entry is: &nbsp; $W(I = 1) =$ <b>BA</b>.
  
  
{Welche Aussagen gelten für die Codierschritte&nbsp; $i = 2$&nbsp; und&nbsp; $i = 3$?
+
{Which statements are true for the coding steps&nbsp; $i = 2$&nbsp; and&nbsp; $i = 3$?
 
|type="[]"}
 
|type="[]"}
+ Für&nbsp; $i = 2$&nbsp; gilt: &nbsp; Ausgabe&nbsp; $(0,$ <b>A</b>$)$, &nbsp; Eintrag&nbsp; $W(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&nbsp; $i = 3$&nbsp; gilt: &nbsp; Ausgabe&nbsp; $(0,$ <b>R</b>$)$, &nbsp; Eintrag&nbsp; $W(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&nbsp; $i = 4$?
+
{Which statements are true for the coding step&nbsp; $i = 4$?
 
|type="[]"}
 
|type="[]"}
- Bei Schritt&nbsp; $i = 4$&nbsp; wird&nbsp; <b>BAR</b>&nbsp; gemeinsam codiert.
+
- At step&nbsp; $i = 4$&nbsp; &nbsp; <b>BAR</b>&nbsp; is coded together.
+ Bei Schritt&nbsp; $i = 4$&nbsp; wird&nbsp; <b>BA</b>&nbsp; gemeinsam codiert.
+
+ At step&nbsp; $i = 4$&nbsp; &nbsp; <b>BA</b>&nbsp; is coded together.
- Die Coderausgabe lautet: &nbsp; $(2,$ <b>AR</b>$)$.
+
- The coder output is: &nbsp; $(2,$ <b>AR</b>$)$.
+ Die Coderausgabe lautet: &nbsp; $(1,$ <b>A</b>$)$.
+
+ The coder output is: &nbsp; $(1,$ <b>A</b>$)$.
  
  
{Vervollständigen Sie die LZ78&ndash;Codierung.&nbsp; Nach welchem Codierschritt&nbsp; $i_{\rm Ende}$&nbsp; ist&nbsp; <b>BARBARA&ndash;BAR</b>&nbsp; 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_{\rm Ende} \ = \ $ { 7 3% }
+
$i_{\rm end} \ = \ $ { 7 3% }
  
  
{Wieviele Binärzeichen benötigt man, um&nbsp; <b>BARBARA&ndash;BAR</b>&nbsp; zu codieren?&nbsp; 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="{}"}
$\text{ohne Codierung:  }\ N \ = \ $ { 22 3% } $\ \rm Bit$
+
$\text{without coding:  }\ N \ = \ $ { 22 3% } $\ \rm bits$
$\text{mit LZ78-Codierung:  }\ N \ = \ $ { 35 3% } $\ \rm Bit$
+
$\text{with LZ78 coding:  }\ N \ = \ $ { 35 3% } $\ \rm bits$
  
  
Line 82: Line 84:
 
</quiz>
 
</quiz>
  
===Musterlösung===
+
===Solution===
 
{{ML-Kopf}}
 
{{ML-Kopf}}
'''(1)'''&nbsp; Zutreffend für den LZ78&ndash;Algorithmus ist <u>Aussage 1</u>:  
+
'''(1)'''&nbsp; <u>Statement 1</u> applies to the LZ78 algorithm:
*Die Vorbelegung gemäß Aussage 2 gilt dagegen für den LZW&ndash;Algorithmus, der 1983 gemeinsam mit Terry Welch veröffentlicht wurde.
+
*In contrast, the preassignment according to statement 2 is true for the LZW algorithm, which was published in 1983 together with Terry Welch.
 +
 
 +
 
 +
 
 +
 
 +
'''(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.
 +
 
 +
 
 +
 
 +
'''(3)'''&nbsp; Here <u>both statements</u> are true.
  
  
'''(2)'''&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. Aussage 3 trifft wieder für die LZW&ndash;Komprimierung zu.
 
  
 +
'''(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.
  
'''(3)'''&nbsp; Hier treffen <u>beide Aussagen</u> zu.
 
  
  
'''(4)'''&nbsp; Richtig sind die <u>Aussagen 2 und 4</u>:
+
[[File:EN_Inf_A_2_3f.png|right|frame|LZ78 coding of&nbsp; "<b>BARBARA–BAR</b>"]]
*Im Wörterbuch wird unter dem Index $I = 1$ das Zeichen <b>B</b> gefunden.
+
'''(5)'''&nbsp; The entire coding process is summarised in the table on the right.&nbsp; One can see:
*Das nächste Zeichen <b>A</b> der Eingangsfolge wird angehängt: &nbsp; <b>(1, A)</b>.
+
* At each time&nbsp; $i$,&nbsp; the edited string is entered into the dictionary.
*Die Aussage 3 kann schon deshalb nicht stimmen, da $Z$ nur ein Zeichen sein kann und keine Zeichenfolge.
+
* At time&nbsp; $\underline{i=7}$&nbsp; the coding process is completed.
  
  
:[[File:Inf_A_2_3f_version2.png|right|frame|LZ78–Codierung von <b>BARBARA–BAR</b>]]
 
'''(5)'''&nbsp; Der gesamte Codiervorgang ist in einer Tabelle zusammengefasst. Man erkennt:
 
* Zu jedem Zeitpunkt $i$ wird die bearbeitete Zeichenfolge in das Wörterbuch eingetragen.
 
* Zum Zeitpunkt $\underline{i=7}$ ist der Codiervorgang abgeschlossen.
 
  
 +
'''(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}$.
  
'''(6)'''&nbsp; Stellt man alle Indizes mit drei Bit dar und die vier Zeichen (Character) mit je zwei Bit, so kommt man zu folgenden Ergebnissen:
 
* ohne Codierung: &nbsp; $N = 11 \cdot 2 \hspace{0.15cm}\underline {= 22 \, \rm Bit}$,
 
* mit LZ78&ndash;Codierung: &nbsp; $N = 7 \cdot (3+2) \hspace{0.15cm}\underline {= 35 \, \rm Bit}$.
 
  
Daran erkennt man:
+
You can see from this:
* 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.
+
* 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.
* Mit variabler Bitanzahl für den Index entsprechend der Aufgabe 2.4 würde sich für dieses LZ78-Beispiel ergeben:
+
* 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 Bit}\hspace{0.05cm}.$$
+
:$$N = 1 \cdot 3 + 2 \cdot 4 + 4 \cdot 5 = 31 \,{\rm bits}\hspace{0.05cm}.$$
 
{{ML-Fuß}}
 
{{ML-Fuß}}
  
Line 121: Line 132:
  
  
[[Category:Aufgaben zu Informationstheorie|^2.2 Verfahren von Lempel, Ziv, 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}.$$