Difference between revisions of "Aufgaben:Exercise 2.4Z: LZW Coding and Decoding again"

From LNTwww
 
(32 intermediate revisions by 5 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_ID2437__Inf_Z_2_4.png|right|]]
+
[[File:EN_Inf_Z2.4_vers2.png|right|frame|Two snapshots of the LZW dictionary ]]
:Die obere Grafik zeigt eine Momentaufnahme des Wörterbuchs, das während der LZW&ndash;Codierung der Eingangssymbolfolge <b>ABABABBAA</b> entsteht. Das untere Wörterbuch entsteht bei der LZW&ndash;Codierung der Sequenz <b>ABABABABA</b>. In beiden Fällen wird vorausgesetzt, dass keine andere Zeichen als <b>A</b> und <b>B</b> vorkommen.
+
The graph shows snapshots of the dictionary created during LZW coding of the input symbol sequence.
 +
*The upper graph is for input symbol sequence&nbsp; <b>ABABABBAA</b>.  
 +
*The lower dictionary is created during LZW coding of the sequence&nbsp; <b>ABABABABA</b>.  
  
:Gleiche Wörterbücher entstehen bei der LZW&ndash;Decodierung, doch erfolgen dann die Wörterbucheinträge erst einen Schritt später. In der Teilaufgabe (3) wird gefragt, für welchen Codierschritt bzw. für welchen Decodierschritt die dargestellten Momentaufnahmen gültig sind.
 
  
:Bei der LZW&ndash;Codierung wird zu jedem Codierschritt <i>i</i> ein Index <i>I</i> ausgewählt und (binär) übertragen. Das Zeichenpaar <b>AB</b> wird bei den beiden Wörterbüchern durch den Index <i>I</i> = 2 dargestellt. Wir betrachten hier den Index <i>I</i> als Dezimalzahl und lassen bei dieser Aufgabe die Binärdarstellung außer Betracht.
+
In both cases, it is assumed that no characters other than&nbsp; <b>A</b>&nbsp; and&nbsp; <b>B</b>&nbsp; can occur at later times.
  
:Bei der LZW&ndash;Decodierung wird in gleicher Weise mit Hilfe des Wörterbuchs aus jedem Index <i>I</i> ein Zeichen bzw. eine Zeichenfolge generiert, zum Beispiel führt <i>I</i> = 1 zum Zeichen <b>B</b> und <i>I</i> = 2 zum Zeichenpaar <b>AB</b>.
+
In <u>LZW decoding</u>, the same dictionaries are created, but then the dictionary entries occur one step later.&nbsp; In subtask&nbsp; '''(3)'''&nbsp; the question is asked for which coding step or for which decoding step the two snapshots shown are valid.
  
:Wird  tatsächlich ein Wörterbucheintrag mit dem gewünschten Index <i>I</i> gefunden, so läuft die Decodierung problemlos ab. Dies ist aber nicht immer so:
 
  
:* Wird bei der Codierung beim Schritt <i>i</i> ein neuer Index <i>I</i> eingetragen und ist dieses <i>I</i> gleichzeitig das Codierergebnis des Schrittes, so ist dieser Index beim Decodierschritt <i>i</i> im Wörterbuch noch nicht belegt. Der Grund dafür ist, dass  beim Decoder die Einträge um einen Schritt später erfolgen.
+
In <u>LZW coding</u>, an index&nbsp; $I$&nbsp; is selected for each coding step&nbsp; $i$&nbsp; and transmitted (binary).&nbsp; The character pair&nbsp; <b>AB</b>&nbsp; is represented by the index&nbsp;  $I = 2$&nbsp; in the two dictionaries.&nbsp; Here we consider the index&nbsp; $I$&nbsp; as a decimal number and leave the binary representation out of consideration for this task.
  
:* Bei binärer Eingangsfolge (alle Zeichen seien <b>A</b> oder <b>B</b>) ist bei der LZW&ndash;Decodierung genau immer dann eine Sonderregelung anzuwenden, wenn im Codierschritt <i>i</i> der Eintrag mit dem Index <i>I</i> = <i>i</i> vorgenommen wurde.
 
  
:Diese Sonderregelung soll an einem Beispiel veranschaulicht werden:
+
With <u>LZW decoding</u>, a character or character sequence is generated in the same way from each index&nbsp; $I$&nbsp; with the help of the dictionary, for example&nbsp; $I = 1$&nbsp; leads to the character&nbsp; <b>B</b>&nbsp; and&nbsp; $I = 2$&nbsp; to the character pair&nbsp; <b>AB</b>.
  
:* Zum Schritt <i>i</i> gibt es keinen zum Index <i>I</i> passenden Eintrag im Decoder&ndash;Wörterbuch.
+
If a dictionary entry with the desired index&nbsp; $I$&nbsp; is actually found, the decoding runs smoothly.&nbsp; However, this is not always the case:
 +
* If a new index&nbsp; $I$&nbsp; is entered during encoding at step&nbsp; $i$&nbsp; and this&nbsp; $I$&nbsp; is at the same time the encoding result of the step, this index is not yet occupied in the dictionary at decoding step&nbsp; $i$&nbsp;.&nbsp; The reason for this is that with the decoder the entries are made one step later than with the coder.
 +
* In the case of a&nbsp; "binary"&nbsp; input sequence&nbsp; $($all characters are&nbsp; <b>A</b>&nbsp; or&nbsp; <b>B</b>$)$,&nbsp; a special rule must always be applied in LZW decoding if the entry with index&nbsp; $I = i$&nbsp; was made in coding step&nbsp; $i$&nbsp;.
  
:* Wir nehmen an, dass das Decodierergebnis beim vorherigen Schritt (<i>i</i> &ndash; 1) <b>ABBABA</b> war.
 
  
:* Dann ergänzt man diese Zeichenfolge um das erste Zeichen der Folge. Hier: <b>ABBABAA</b>.
+
This special rule shall be illustrated by an example:
 +
* For step&nbsp; $i$&nbsp; there is no entry in the decoder dictionary matching index&nbsp; $I$&nbsp;.
 +
* We assume that in the previous step&nbsp; $(i- 1)$&nbsp; the decoding result was&nbsp; <b>ABBABA</b>&nbsp;.
 +
* Then we add the first character of the sequence to this string. &nbsp; Here:&nbsp; <b>ABBABAA</b>.
 +
* Then one enters the sequence&nbsp; <b>ABBABAA</b>&nbsp; into the dictionary under index&nbsp; $I$&nbsp;.
  
:* Anschließend trägt man die Sequenz <b>ABBABAA</b> in das Wörterbuch unter dem Index <i>I</i> ein.
 
  
:<b>Hinweis:</b> Die Aufgabe gehört zum Themengebiet von Kapitel 2.2. Beachten Sie bei der Lösung dieser Aufgabe, dass beim LZW&ndash;Algorithmus nicht von einem leeren Wörterbuch ausgegangen wird. Vielmehr beinhalten die Indizes <i>I</i> = 0 bis <i>I</i> = <i>M</i>&ndash;1 alle <i>M</i> zulässigen Zeichen.
 
  
===Fragebogen===
+
 
 +
 
 +
 
 +
 
 +
 
 +
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 pages&nbsp;
 +
:: [[Information_Theory/Komprimierung_nach_Lempel,_Ziv_und_Welch#LZ77_-_the_basic_form_of_the_Lempel-Ziv_algorithms|LZ77 - the basic form of Lempel-Ziv algorithms]],
 +
:: [[Information_Theory/Komprimierung_nach_Lempel,_Ziv_und_Welch#Lempel-Ziv_coding_with_variable_index_bit_length|Lempel-Ziv coding with variable index bit length]],
 +
:: [[Information_Theory/Komprimierung_nach_Lempel,_Ziv_und_Welch#Decoding_of_the_LZW_algorithm|Decoding of the LZW algorithm]].
 +
 
 +
*Also, when solving this task, note that the LZW algorithm does not assume an empty dictionary.
 +
*Rather, the indices&nbsp; $I = 0$&nbsp; to&nbsp; $I = M- 1$&nbsp; contain all&nbsp; $M$&nbsp; permissible characters of the alphabet.
 +
 
 +
===Questions===
  
 
<quiz display=simple>
 
<quiz display=simple>
{Codieren Sie die Eingangsfolge <b>ABABABBAA</b>. Welche Indizes ergeben sich zu den Schritten <i>i</i> = 1, ... , 5?
+
{Encode the input sequence&nbsp; <b>ABABABBAA</b>&nbsp; according to the <u>above diagram</u>.&nbsp; Which indices&nbsp; $I_i$&nbsp; result for the steps&nbsp; $i=1$, ... , $i=5$?
 
|type="{}"}
 
|type="{}"}
<b>ABABABBAA</b>$,i = 1:\ I$ = { 0 3% }
+
$I_1 \ = \ $ { 0. }
$i = 2:\ I$ = { 1 3% }
+
$I_2 \ = \ $ { 1 }
$i = 3:\ I$ = { 2 3% }
+
$I_3 \ = \ $ { 2 }
$i = 4:\ I$ = { 2 3% }
+
$I_4 \ = \ $ { 2 }
$i = 5:\ I$ = { 3 3% }
+
$I_5 \ = \ $ { 3 }
  
  
{Codieren Sie nun die Eingangsfolge <b>ABABABABA</b>. Geben Sie die Indizes zu den Schritten <i>i</i> = 4 und <i>i</i> = 5 an.
+
 
 +
{Now encode the input sequence&nbsp; <b>ABABABABA</b>&nbsp; according to the <u>diagram below</u>.&nbsp; Specify the indices&nbsp; $I_i$&nbsp; for the steps&nbsp; $i=4$&nbsp; and&nbsp; $i=5$&nbsp;.
 
|type="{}"}
 
|type="{}"}
<b>ABABABBAA</b> $i = 4:\ I$ = { 4 3% }
+
$I_4 \ = \ $ { 4 }
$i = 5:\ I$ = { 3 3% }
+
$I_5 \ = \ $ { 3 }
  
  
{Für welchen Schritt (<i>i</i>) gilt die Momentaufnahme des auf der Angabenseite dargestellten Wörterbuchs bezüglich
+
{For which step&nbsp; $i$&nbsp; does the snapshot of the dictionary shown on the exercise description page apply with respect to
 
|type="{}"}
 
|type="{}"}
$Codierung:\ i$ = { 4 3% }
+
$\text{Encoding:} \ \ i \ = \ $ { 4 }
$Decodierung:\ i$ = { 5 3% }
+
$\text{Decoding:} \ \ i \ = \ $ { 5 }
  
  
{Wann muss man auf die Decodier&ndash;Sonderfallregelung zurückgreifen?
+
{When does one have to resort to the decoding special case rule?
 
|type="[]"}
 
|type="[]"}
- Bei der Decodierung von <b>ABABABBAA</b> im Schritt <i>i</i> = 4.
+
- When decoding&nbsp; <b>ABABABBAA</b>&nbsp; in step&nbsp; $i = 4$.
+ Bei der Decodierung von <b>ABABABABA</b> im Schritt <i>i</i> = 4.
+
+ When decoding&nbsp; <b>ABABABABA</b>&nbsp; in step&nbsp; $i = 4$.
- Bei der Decodierung von <b>ABABABABA</b> im Schritt <i>i</i> = 5.
+
- When decoding&nbsp; <b>ABABABABA</b>&nbsp; in step&nbsp; $i = 5$.
  
  
Line 64: Line 82:
 
</quiz>
 
</quiz>
  
===Musterlösung===
+
===Solution===
 
{{ML-Kopf}}
 
{{ML-Kopf}}
:<b>1.</b>&nbsp;&nbsp;Wir bezeichnen mit <i>W</i>(<i>I</i>) ein Feld (Array), welches das Wörterbuch beschreibt und dessen Elemente Character oder Zeichenfolgen beinhalten.  Die Codierung von <b>ABABABBAA</b> läuft wie folgt ab:
+
'''(1)'''&nbsp; We use&nbsp; $W(I)$&nbsp; to denote a field (array),&nbsp; that describes the dictionary and whose elements contain characters or strings. &nbsp;
 
 
:* <i>i</i> = 1: <b>A</b> &nbsp;&nbsp;&nbsp;&#8594;&nbsp;&nbsp; <u><i>I</i> = 0</u>, <i>W</i>(<i>I</i> = 2) = <b>AB</b>,
 
 
 
:* <i>i</i> = 2: <b>B</b> &nbsp;&nbsp;&nbsp;&#8594;&nbsp;&nbsp; <u><i>I</i> = 1</u>, <i>W</i>(<i>I</i> = 3) = <b>BA</b>,
 
 
 
:* <i>i</i> = 3: <b>AB</b> &#8594;&nbsp;&nbsp; <u><i>I</i> = 2</u>, <i>W</i>(<i>I</i> = 4) = <b>ABA</b>,
 
  
:* <i>i</i> = 4: <b>AB</b> &#8594;&nbsp;&nbsp; <u><i>I</i> = 2</u>, <i>W</i>(<i>I</i> = 5) = <b>ABB</b>,
+
*The encoding of&nbsp; <b>ABABABBAA</b>&nbsp; proceeds as follows:
 +
:: $i = 1$: &nbsp; &nbsp; <b>A</b> &nbsp;&nbsp;&nbsp;&#8594;&nbsp;&nbsp; $\underline{I=0}$, &nbsp; $W(I = 2) =$ <b>AB</b>,
 +
:: $i = 2$: &nbsp; &nbsp; <b>B</b> &nbsp;&nbsp;&nbsp;&#8594;&nbsp;&nbsp; $\underline{I=1}$, &nbsp; $W(I = 3) =$ <b>BA</b>,
 +
:: $i = 3$: &nbsp; &nbsp; <b>AB</b> &#8594;&nbsp;&nbsp; $\underline{I=2}$, &nbsp; $W(I = 4) =$ <b>ABA</b>,
 +
:: $i = 4$: &nbsp; &nbsp; <b>AB</b> &#8594;&nbsp;&nbsp; $\underline{I=2}$, &nbsp; $W(I = 5) =$ <b>ABB</b>,
 +
:: $i = 5$: &nbsp; &nbsp; <b>BA</b> &#8594;&nbsp;&nbsp; $\underline{I=3}$, &nbsp; $W(I = 6) =$ <b>BAA</b>.
  
:* <i>i</i> = 5: <b>BA</b> &#8594;&nbsp;&nbsp; <u><i>I</i> = 3</u>, <i>W</i>(<i>I</i> = 6) = <b>BAA</b>.
+
*Note that the last character&nbsp; $($<b>A</b>$)$&nbsp; of the input string&nbsp; <b>ABABABBAA</b>&nbsp; at time&nbsp; $i = 5$&nbsp; is already considered in the dictionary entry but has not yet been encoded.
  
:Es ist anzumerken, dass das letzte Zeichen (<b>A</b>) des Eingabestrings <b>ABABABBAA</b> zum Zeitpunkt <i>i</i> = 5 zwar bereits beim Wörterbucheintrag berücksichtigt ist, aber noch nicht codiert wurde.
 
  
:<b>2.</b>&nbsp;&nbsp;Für die Schritte 1 bis 3 ändert sich nichts gegenüber der Teilaufgabe (1). Danach gilt:
 
  
:* <i>i</i> = 4: <b>ABA</b> &#8594;&nbsp;&nbsp; <u><i>I</i> = 4</u>, Wörterbuch (<i>I</i> = 5) = <b>ABAB</b>,
+
'''(2)'''&nbsp; For the steps&nbsp; $i = 1$&nbsp; to&nbsp; $i = 3$&nbsp; nothing changes compared to subtask&nbsp; '''(1)'''.
 +
*Afterwards, the following applies:
 +
:: $i = 4$: &nbsp; &nbsp; <b>ABA</b> &#8594;&nbsp;&nbsp; $\underline{I=4}$, &nbsp; $W(I = 5) =$ <b>ABAB</b>,
 +
:: $i = 5$: &nbsp; &nbsp; <b>BA</b> &#8594;&nbsp;&nbsp; $\underline{I=3}$, &nbsp; encoding completed, no new dictionary entry possible.
  
:* <i>i</i> = 5: <b>BA</b> &nbsp;&nbsp;&nbsp;&#8594;&nbsp;&nbsp; <u><i>I</i> = 3</u>, Codierung abgeschlossen, kein neuer Wörterbucheintrag möglich.
 
  
:<b>3.</b>&nbsp;&nbsp;Der Vergleich mit den obigen Ergebnissen zeigt, dass das Wörterbuch des Coders genau nach <u><i>i</i> = 4</u> Codierschritten die gezeigten Einträge aufweist. Beim Decoder ergibt sich demgegenüber eine Zeitverzögerung um einen Schritt: <u><i>i</i> = 5</u>.
 
  
:<b>4.</b>&nbsp;&nbsp;Die Sonderfallregelung der Decodierung ist (im vorliegenden Beispiel) dann notwendig, wenn im Codierschritt <i>i</i> der Index <i>I</i> = <i>i</i> ausgegeben wird. Bei der Decodierung findet er dann die erforderliche Zuordnung Index &#8594; Zeichenfolge nicht, da das generierte Wörterbuch zum Zeitpunkt <i>i</i> nur Einträge mit Indizes <i>I</i> < <i>i</i> enthält.
+
'''(3)'''&nbsp; The comparison with above results shows:
 +
*The dictionary of the&nbsp; <u>encoder</u>&nbsp; has the entries shown exactly after&nbsp; $\underline{i=4}$&nbsp; encoding steps.  
 +
*With the&nbsp; <u>decoder</u>, on the other hand, there is a time delay of one step:  &nbsp; $\underline{i=5}$.
  
:Für die Folge <b>ABABABBAA</b> gilt entsprechend Teilaufgabe 1) stets <i>I</i> < <i>i</i>. Dagegen ergäbe sich bei der Folge <b>ABABABABA</b> folgende Indizes:
 
:$$i = 1\hspace{-0.15cm}: I = 0\hspace{0.05cm},
 
\hspace{0.2cm}i = 2\hspace{-0.15cm}: I = 1\hspace{0.05cm},
 
\hspace{0.2cm}i = 3\hspace{-0.15cm}: I = 2\hspace{0.05cm},
 
\hspace{0.2cm}\underline{i = 4\hspace{-0.15cm}: I = 4}\hspace{0.05cm},
 
\hspace{0.2cm}i = 5\hspace{-0.15cm}: I = 3\hspace{0.05cm}.  $$
 
:Richtig ist dementsprechend der <u>Lösungsvorschlag 2</u>.
 
  
:Hier noch zusammenfassend die gesamte Decodierung von <b>ABABABABA</b>. Die Vorbelegung des Wörterbuchs beinhaltet <i>I</i> = 0: <b>A</b> und <i>I</i> = 1: <b>B</b>. Dann gilt mit dem Wörterbuch&ndash;Array <i>W</i>(<i>I</i>):
 
  
:* <i>i</i> = 1: Decodierung <i>I</i> = 0 &#8594; <b>A</b>,
 
  
:* <i>i</i> = 2: Decodierung <i>I</i> = 1 &#8594; <b>B</b>, &nbsp;&nbsp;&nbsp;<i>W</i>(<i>I</i> = 2) = <b>AB</b>,
+
'''(4)'''&nbsp; <u>Solution suggestion 2</u> is correct:
 +
*The special case regulation of the decoding is necessary&nbsp; (in the present example)&nbsp; if the index&nbsp; $I =i$&nbsp; is output in the coding step&nbsp; $i$&nbsp;.
 +
*During decoding, it then does not find the required assignment&nbsp; "Index&nbsp; &#8594;&nbsp; String"&nbsp; since the generated dictionary at time&nbsp; $i$&nbsp; only contains entries with&nbsp; $I < i$&nbsp;.
 +
*For the sequence&nbsp; <b>ABABABBAA</b> &nbsp; &rArr; &nbsp; $I < i$ always applies according to subtask&nbsp; '''(1)'''&nbsp;.
 +
*In contrast, the following indices would result for the sequence&nbsp; <b>ABABABABA</b>&nbsp;:
 +
:$$i = 1\hspace{-0.15cm}: \hspace{0.15cm} I = 0\hspace{0.05cm},
 +
\hspace{0.5cm}i = 2\hspace{-0.15cm}: \hspace{0.15cm}I = 1\hspace{0.05cm},
 +
\hspace{0.5cm}i = 3\hspace{-0.15cm}: \hspace{0.15cm}I = 2\hspace{0.05cm},
 +
\hspace{0.5cm}\underline{i = 4\hspace{-0.15cm}: \hspace{0.15cm}I = 4}\hspace{0.05cm},  
 +
\hspace{0.5cm}i = 5\hspace{-0.15cm}: \hspace{0.15cm}I = 3\hspace{0.05cm}.  $$
  
:* <i>i</i> = 3: Decodierung <i>I</i> = 2 &#8594; <b>AB</b>, <i>W</i>(<i>I</i> = 3) = <b>BA</b>,
+
Here is a summary of the entire decoding process of&nbsp; <b>ABABABABA</b>:
  
:* <i>i</i> = 4: Ein Eintrag mit dem Index <i>I</i> = 4 ist nicht vorhanden &#8658; Sonderfallregelung. Man nimmt das letzte Decodierergebnis (hier <b>AB</b>) und fügt das erste Zeichen dieser Sequenz hinten an &#8658; <b>ABA</b>. Danach wird <b>ABA</b> im Wörterbuch unter dem Index <i>I</i> = 4 abgelegt.
+
*The pre-assignment of the dictionary includes&nbsp; $(I=0$:&nbsp; <b>A</b>$)$ &nbsp; &nbsp; and&nbsp; $(I=1$:&nbsp; <b>B</b>$)$.  
  
:* <i>i</i> = 5: Decodierung <i>I</i> = 3 &#8594; <b>BA</b>. Ende der Decodereingangsfolge.
+
*Then with the dictionary array&nbsp; $W(I)$:
 +
:: $i = 1$: &nbsp; &nbsp; Decoding &nbsp; $I=0$ &nbsp; &#8594; &nbsp; <b>A</b>,
 +
:: $i = 2$: &nbsp; &nbsp; Decoding&nbsp; $I=1$ &nbsp; &#8594; &nbsp; <b>B</b>, &nbsp; &nbsp; &nbsp; $W(I = 2) =$ <b>AB</b>,
 +
:: $i = 3$: &nbsp; &nbsp; Decoding&nbsp; $I=2$ &nbsp; &#8594; &nbsp; <b>AB</b>, &nbsp;&nbsp;&nbsp; $W(I = 3) =$ <b>BA</b>,
 +
:: $i = 4$: &nbsp; &nbsp; An entry with index&nbsp; $I = 4$&nbsp; is not present &nbsp; &#8658; &nbsp; '''Special case rule''': <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; One takes the last decoding result&nbsp; $($here&nbsp; <b>AB</b>$)$ and adds the first character of this sequence at the end &nbsp; &#8658; &nbsp; <b>ABA</b>. <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Then&nbsp; <b>ABA</b>&nbsp; is stored in the dictionary under&nbsp; index&nbsp; $I = 4$&nbsp;.
 +
:: $i = 5$: &nbsp; &nbsp; Decoding &nbsp; $I=3$ &nbsp; &#8594; &nbsp; <b>BA</b>. &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  '''End of the decoder input sequence'''.
 
{{ML-Fuß}}
 
{{ML-Fuß}}
  
  
  
[[Category:Aufgaben zu Informationstheorie|^2.2 Komprimierung nach Lempel, Ziv und Welch^]]
+
[[Category:Information Theory: Exercises|^2.2 Lempel-Ziv-Welch Compression^]]

Latest revision as of 11:34, 31 August 2021

Two snapshots of the LZW dictionary

The graph shows snapshots of the dictionary created during LZW coding of the input symbol sequence.

  • The upper graph is for input symbol sequence  ABABABBAA.
  • The lower dictionary is created during LZW coding of the sequence  ABABABABA.


In both cases, it is assumed that no characters other than  A  and  B  can occur at later times.

In LZW decoding, the same dictionaries are created, but then the dictionary entries occur one step later.  In subtask  (3)  the question is asked for which coding step or for which decoding step the two snapshots shown are valid.


In LZW coding, an index  $I$  is selected for each coding step  $i$  and transmitted (binary).  The character pair  AB  is represented by the index  $I = 2$  in the two dictionaries.  Here we consider the index  $I$  as a decimal number and leave the binary representation out of consideration for this task.


With LZW decoding, a character or character sequence is generated in the same way from each index  $I$  with the help of the dictionary, for example  $I = 1$  leads to the character  B  and  $I = 2$  to the character pair  AB.

If a dictionary entry with the desired index  $I$  is actually found, the decoding runs smoothly.  However, this is not always the case:

  • If a new index  $I$  is entered during encoding at step  $i$  and this  $I$  is at the same time the encoding result of the step, this index is not yet occupied in the dictionary at decoding step  $i$ .  The reason for this is that with the decoder the entries are made one step later than with the coder.
  • In the case of a  "binary"  input sequence  $($all characters are  A  or  B$)$,  a special rule must always be applied in LZW decoding if the entry with index  $I = i$  was made in coding step  $i$ .


This special rule shall be illustrated by an example:

  • For step  $i$  there is no entry in the decoder dictionary matching index  $I$ .
  • We assume that in the previous step  $(i- 1)$  the decoding result was  ABBABA .
  • Then we add the first character of the sequence to this string.   Here:  ABBABAA.
  • Then one enters the sequence  ABBABAA  into the dictionary under index  $I$ .





Hints:

LZ77 - the basic form of Lempel-Ziv algorithms,
Lempel-Ziv coding with variable index bit length,
Decoding of the LZW algorithm.
  • Also, when solving this task, note that the LZW algorithm does not assume an empty dictionary.
  • Rather, the indices  $I = 0$  to  $I = M- 1$  contain all  $M$  permissible characters of the alphabet.

Questions

1

Encode the input sequence  ABABABBAA  according to the above diagram.  Which indices  $I_i$  result for the steps  $i=1$, ... , $i=5$?

$I_1 \ = \ $

$I_2 \ = \ $

$I_3 \ = \ $

$I_4 \ = \ $

$I_5 \ = \ $

2

Now encode the input sequence  ABABABABA  according to the diagram below.  Specify the indices  $I_i$  for the steps  $i=4$  and  $i=5$ .

$I_4 \ = \ $

$I_5 \ = \ $

3

For which step  $i$  does the snapshot of the dictionary shown on the exercise description page apply with respect to

$\text{Encoding:} \ \ i \ = \ $

$\text{Decoding:} \ \ i \ = \ $

4

When does one have to resort to the decoding special case rule?

When decoding  ABABABBAA  in step  $i = 4$.
When decoding  ABABABABA  in step  $i = 4$.
When decoding  ABABABABA  in step  $i = 5$.


Solution

(1)  We use  $W(I)$  to denote a field (array),  that describes the dictionary and whose elements contain characters or strings.  

  • The encoding of  ABABABBAA  proceeds as follows:
$i = 1$:     A    →   $\underline{I=0}$,   $W(I = 2) =$ AB,
$i = 2$:     B    →   $\underline{I=1}$,   $W(I = 3) =$ BA,
$i = 3$:     AB →   $\underline{I=2}$,   $W(I = 4) =$ ABA,
$i = 4$:     AB →   $\underline{I=2}$,   $W(I = 5) =$ ABB,
$i = 5$:     BA →   $\underline{I=3}$,   $W(I = 6) =$ BAA.
  • Note that the last character  $($A$)$  of the input string  ABABABBAA  at time  $i = 5$  is already considered in the dictionary entry but has not yet been encoded.


(2)  For the steps  $i = 1$  to  $i = 3$  nothing changes compared to subtask  (1).

  • Afterwards, the following applies:
$i = 4$:     ABA →   $\underline{I=4}$,   $W(I = 5) =$ ABAB,
$i = 5$:     BA →   $\underline{I=3}$,   encoding completed, no new dictionary entry possible.


(3)  The comparison with above results shows:

  • The dictionary of the  encoder  has the entries shown exactly after  $\underline{i=4}$  encoding steps.
  • With the  decoder, on the other hand, there is a time delay of one step:   $\underline{i=5}$.



(4)  Solution suggestion 2 is correct:

  • The special case regulation of the decoding is necessary  (in the present example)  if the index  $I =i$  is output in the coding step  $i$ .
  • During decoding, it then does not find the required assignment  "Index  →  String"  since the generated dictionary at time  $i$  only contains entries with  $I < i$ .
  • For the sequence  ABABABBAA   ⇒   $I < i$ always applies according to subtask  (1) .
  • In contrast, the following indices would result for the sequence  ABABABABA :
$$i = 1\hspace{-0.15cm}: \hspace{0.15cm} I = 0\hspace{0.05cm}, \hspace{0.5cm}i = 2\hspace{-0.15cm}: \hspace{0.15cm}I = 1\hspace{0.05cm}, \hspace{0.5cm}i = 3\hspace{-0.15cm}: \hspace{0.15cm}I = 2\hspace{0.05cm}, \hspace{0.5cm}\underline{i = 4\hspace{-0.15cm}: \hspace{0.15cm}I = 4}\hspace{0.05cm}, \hspace{0.5cm}i = 5\hspace{-0.15cm}: \hspace{0.15cm}I = 3\hspace{0.05cm}. $$

Here is a summary of the entire decoding process of  ABABABABA:

  • The pre-assignment of the dictionary includes  $(I=0$:  A$)$     and  $(I=1$:  B$)$.
  • Then with the dictionary array  $W(I)$:
$i = 1$:     Decoding   $I=0$   →   A,
$i = 2$:     Decoding  $I=1$   →   B,       $W(I = 2) =$ AB,
$i = 3$:     Decoding  $I=2$   →   AB,     $W(I = 3) =$ BA,
$i = 4$:     An entry with index  $I = 4$  is not present   ⇒   Special case rule:
                  One takes the last decoding result  $($here  AB$)$ and adds the first character of this sequence at the end   ⇒   ABA.
                  Then  ABA  is stored in the dictionary under  index  $I = 4$ .
$i = 5$:     Decoding   $I=3$   →   BA.             End of the decoder input sequence.