Difference between revisions of "Aufgaben:Exercise 2.3Z: About the LZ77 Coding"

From LNTwww
 
(31 intermediate revisions by 4 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_ID2436__Inf_Z_2_3.png|right|]]
+
[[File:P_ID2436__Inf_Z_2_3.png|right|frame|Sliding–Window with&nbsp; $G = 4$&nbsp; and&nbsp; $G = 5$<br>(valid for "LZ77")]]
:In der Aufgabe A2.3 sollten Sie <b>BARBARA&ndash;BAR</b> (String der Länge 11, vier verschiedene Zeichen) mit dem LZ78&ndash;Algorithmus komprimieren. In dieser Aufgabe verwenden wir den gleichen Text zur Demonstration der LZ77&ndash;Komprimierung.
+
In&nbsp; [[Aufgaben:Exercise_2.3:_About_the_LZ78_Compression|Exercise 2.3]],&nbsp; you were supposed to compress&nbsp; "<b>BARBARA&ndash;BAR</b>"&nbsp; (string of length&nbsp; $11$, four different characters)&nbsp; using the LZ78 algorithm.&nbsp;  
  
:Anzumerken ist:
+
In this exercise we use the same text to demonstrate LZ77 compression.&nbsp; To note:
 +
* While the successor&nbsp; "LZ78"&nbsp; successively builds a global dictionary,&nbsp; "LZ77"&nbsp; uses a local dictionary.
 +
* The LZ77 method works with a&nbsp; "Sliding Window"&nbsp; that is gradually shifted over the input text.
 +
* This&nbsp; "sliding window"&nbsp; is divided into the&nbsp; "preview buffer"&nbsp; (highlighted in blue in the graphic)&nbsp; and the&nbsp; "search buffer"&nbsp; (highlighted in red).&nbsp; Both buffers have a size of&nbsp; $G$&nbsp; memory locations each.
 +
* Each coding step&nbsp; $i$&nbsp; is characterised by a triple&nbsp; $(P,\ L,\ Z)$.&nbsp; Here,&nbsp; $P$&nbsp; and&nbsp; $L$&nbsp; are integers and&nbsp; $Z$&nbsp; is a character.&nbsp; Transmitted are the binary representations of&nbsp; $P$,&nbsp; $L$&nbsp; and&nbsp; $Z$.
 +
* After transmission, the&nbsp; sliding window&nbsp; is shifted one or more positions to the right and the next coding step&nbsp; $i + 1$ begins.
  
:* Während beim Nachfolger LZ78 sukzessive ein globales Wörterbuch aufgebaut wird, verwendet LZ77  ein lokales Wörterbuch.
 
  
:* Das LZ77&ndash;Verfahren arbeitet mit einem <i>Sliding Window</i>, das schrittweise über den Eingabetext verschoben wird.
+
The upper diagram shows the initial allocation with the buffer size&nbsp; $G = 4$&nbsp; at the times&nbsp; $i = 1$&nbsp; as well as&nbsp; $i = 4$.
 +
*At time&nbsp; $i = 1$&nbsp;, the search buffer is empty, so the coder output is&nbsp; $(0, 0,$ <b>B</b>$)$&nbsp;.
 +
*After the shift by one position, the search buffer contains a&nbsp; <b>B</b>, but no string that begins with&nbsp; <b>A</b>.&nbsp; The second number triple is therefore&nbsp; $(0, 0,$ <b>A</b>$)$.
 +
*The output for&nbsp; $i = 3$&nbsp; is&nbsp; $(0, 0,$ <b>R</b>$)$, since there is no string beginning with&nbsp; <b>R</b>&nbsp; in the search buffer even now.
  
:* Dieses &bdquo;gleitende Fenster&rdquo; ist unterteilt in den Vorschaupuffer (in der Grafik blau hinterlegt) und den Suchpuffer (rote Hinterlegung). Beide Puffer haben eine Größe von <i>G</i> Speicherplätzen.
 
  
:* Jeder Codierschritt <i>i</i> wird durch ein Zahlentriple (<i>P</i>, <i>L</i>, <i>Z</i>) charakterisiert. Hierbei sind <i>P</i> und <i>L</i> Integergrößen und <i>Z</i> ein Character. Übertragen werden die Binärdarstellungen von <i>P</i>, <i>L</i> und <i>Z</i>.
+
The snapshot at time&nbsp; $i = 4$&nbsp; is also shown in the graphic.&nbsp; The search is now for the character string in the search buffer that best matches the preview text&nbsp; <b>BARA</b>&nbsp;.&nbsp; A number triple&nbsp; $(P,\ L,\ Z)$, is transmitted again, but now with the following meaning:
 +
* $P$&nbsp; indicates the position in the (red) search buffer where the match starts.&nbsp; The&nbsp; $P$&nbsp; values of the individual memory locations can be seen in the graphic.
 +
* $L$&nbsp; denotes the number of characters in the search buffer that, starting at&nbsp; $P$,&nbsp; match the current string in the preview buffer.
 +
* Finally $Z$&nbsp; denotes the first character in the preview buffer that differs from the matching string found in the search buffer.
  
:* Nach der Übertragung wird das <i>Sliding Window</i> um eine oder mehrere Positionen nach rechts verschoben und es beginnt der nächste Codierschritt <i>i</i> + 1.
 
  
:Die obere Grafik zeigt die Anfangsbelegung mit Puffergröße <i>G</i> = 4 zu den Zeitpunkten <i>i</i> = 1 sowie <i>i</i> = 4. Zum Zeitpunkt <i>i</i> = 1 ist der Suchpuffer leer, so dass die Coderausgabe (0, 0, <b>B</b>) lautet. Nach der Verschiebung um eine Position beinhaltet der Suchpuffer ein <b>B</b>, aber keinen String, der mit <b>A</b> anfängt. Das zweite Zahlentriple ist somit (0, 0, <b>A</b>). Die Ausgabe für <i>i</i> = 3 lautet (0, 0, <b>R</b>), da im Suchpuffer auch jetzt keine Zeichenfolge zu finden ist, die mit <b>R</b> beginnt.
+
The larger the LZ77 parameter&nbsp; $G$&nbsp;, the easier it is to find the longest possible match.&nbsp; In subtask&nbsp; '''(4)'''&nbsp;  you will notice that the LZ77 encoding with&nbsp; $G = 5$&nbsp; gives a better result than the one with&nbsp; $G = 4$.
 +
* However, because of the later binary representation of&nbsp; $P$,&nbsp; one will always choose&nbsp; $G$&nbsp; as a power of two, so that&nbsp; $G$&nbsp; can be represented with&nbsp; $\log_2 \ P$&nbsp; bits&nbsp; $(G = 8$ &nbsp; &#8658; &nbsp; three-digit binary number&nbsp; $P)$.  
 +
*This means that a&nbsp; "Sliding Window"&nbsp; with&nbsp; $G = 5$&nbsp; has rather little practical relevance.
  
:Die Momentaufnahme zum Zeitpunkt <i>i</i> = 4 ist ebenfalls in der Grafik angegeben. Gesucht ist nun die Zeichenfolge im Suchpuffer, die mit dem Vorschautext <b>BARA</b> am besten übereinstimmt. Übertragen wird wieder ein Zahlentriple (<i>P</i>, <i>L</i>, <i>Z</i>), aber nun mit folgender Bedeutung:
 
  
:* <i>P</i> gibt die Position im (roten) Suchpuffer an, bei der die gefundene Übereinstimmung beginnt. Die jeweiligen <i>P</i>&ndash;Werte für die einzelnen Speicherplätze können der Grafik entnommen werden.
 
  
:* <i>L</i> bezeichnet die Anzahl der Zeichen im Suchpuffer, die beginnend bei <i>P</i> mit dem aktuellen String im Vorschaupuffer übereinstimmen.
 
  
:* <i>Z</i> bezeichnet schließlich das erste Zeichen im Vorschaupuffer, das sich vom gefundenen Übereinstimmungs&ndash;String  im Suchpuffer unterscheidet.
+
Hints:
 +
*The task 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#LZ77_-_the_basic_form_of_the_Lempel-Ziv_algorithms|LZ77 &ndash; the basic form of the Lempel-Ziv algorithms]]&nbsp;.
 +
*The original literature&nbsp; [LZ77]&nbsp; on this method is: <br> &nbsp; &nbsp; &nbsp; Ziv, J.; Lempel, A.:&nbsp; A Universal Algorithm for Sequential Data Compression.&nbsp; In: IEEE Transactions on Information Theory, no. 3, vol. 23, 1977, p. 337–343.
 +
 +
*&nbsp; [[Aufgaben:Exercise_2.3:_About_the_LZ78_Compression|Exercise 2.3]]&nbsp; and&nbsp; [[Aufgaben:Exercise_2.4:_About_the_LZW_algorithm|Exercise 2.4]]&nbsp; deal with other Lempel&ndash;Ziv methods in a similar way.
 +
 
  
:Je größer der LZ77&ndash;Parameter <i>G</i> ist, um so leichter findet man eine möglichst lange Übereinstimmung. In der Teilaufgabe (4) werden Sie feststellen, dass die LZ77&ndash;Codierung mit <i>G</i> = 5 ein besseres Ergebnis liefert als diejenige mit <i>G</i> = 4. Aufgrund der nachfolgenden Binärdarstellung von <i>P</i> wird man allerdings <i>G</i> stets als Zweierpotenz wählen, so dass <i>G</i> mit ld <i>P</i> Bit darstellbar ist (<i>G</i> = 8 &nbsp;&#8658;&nbsp; dreistellige Binärzahl <i>P</i>). Das heißt, ein <i>Sliding Window</i> mit <i>G</i> = 5 hat eher einen geringen Praxisbezug.
 
  
:<b>Hinweis:</b> Die Aufgabe gehört zum Themengebiet von Kapitel 2.2.
+
===Questions===
 
 
 
 
===Fragebogen===
 
  
 
<quiz display=simple>
 
<quiz display=simple>
{Wie lautet die LZ77&ndash;Ausgabe mit <i>G</i> = 4 bei Schritt <i>i</i> = 4?
+
{What is the LZ77 output with&nbsp; $G = 4$&nbsp; at step&nbsp; $i = 4$?
|type="[]"}
+
|type="()"}
- (0, 0, <b>B</b>),
+
- $(0, 0,$ <b>B</b>$)$,
- (2, 1, <b>A</b>),
+
- $(2, 1,$ <b>A</b>$)$,
+ (2, 3, <b>A</b>).
+
+ $(2, 3,$ <b>A</b>$)$.
  
  
{Welche Aussage gilt für die gleiche Puffergröße <i>G</i> = 4 bei Schritt <i>i</i> = 5?
+
{Which statement is true for the same buffer size&nbsp; $G = 4$&nbsp; at step&nbsp; $i = 5$?
 
|type="[]"}
 
|type="[]"}
+ Im Suchpuffer steht <b>BARA</b>.
+
+ The search buffer contains&nbsp; "<b>BARA</b>".
+ Im Vorschaupuffer steht <b>&ndash;BAR</b>.
+
+ The preview buffer says&nbsp; "<b>&ndash;BAR</b>".
- Die Ausgabe lautet (0, 0, <b>A</b>).
+
- The output is&nbsp; $(0, 0,$ <b>A</b>$)$.
  
  
{Nach welchem Schritt <i>i</i> ist die Codierung beendet?
+
{After which step&nbsp; $i_{\rm end}$&nbsp; is the coding with&nbsp; $G = 4$&nbsp; finished?
 
|type="{}"}
 
|type="{}"}
$G = 4:\ Nach\ i$ = { 9 3% } $Codierschritten$
+
$i_{\rm end} \ = \ $ { 9 }  
  
  
{Nun gelte <i>G</i> = 5. Nach welchem Schritt <i>i</i> ist dann die Codierung  beendet?
+
{Now let&nbsp; $G = 5$.&nbsp; After which step&nbsp; $i_{\rm end}$&nbsp; is the coding finished?
 
|type="{}"}
 
|type="{}"}
$G = 5:\ Nach\ i$ = { 6 3% } $Codierschritten$
+
$i_{\rm end} \ = \ $ { 6 }  
  
  
{Welche Vorteile hat LZ78 gegenüber LZ77 bei <u>sehr großen</u> Dateien?
+
{What advantages does LZ78 have over LZ77 for "very large" files?
 
|type="[]"}
 
|type="[]"}
+ Man findet häufiger bereits abgelegte Phrasen im Wörterbuch.
+
+ One finds more often already stored phrases in the dictionary.
- Pro Codierschritt müssen weniger Bit übertragen werden.
+
- Fewer bits have to be transferred per coding step.
  
  
Line 69: Line 78:
 
</quiz>
 
</quiz>
  
===Musterlösung===
+
===Solution===
 
{{ML-Kopf}}
 
{{ML-Kopf}}
:<b>1.</b>&nbsp;&nbsp;Richtig ist der <u>Lösungsvorschlag 3</u>. Im Vorschaupuffer steht zum betrachteten Zeitpunkt <i>i</i> = 4 die Zeichenfolge <b>BARA</b>, und im Suchpuffer in den letzten drei Stellen <b>BAR</b>:
+
[[File:P_ID2438__Inf_Z_2_3c.png|right|frame|Example of the LZ77 algorithm with&nbsp; $G = 4$]]
 +
'''(1)'''&nbsp;<u>Solution suggestion 3</u> is correct.  
 +
*The preview buffer contains the character string&nbsp; "<b>BARA</b>" at the time&nbsp; $i = 4$&nbsp;.
 +
*The search buffer contains&nbsp; "<b>BAR</b>" in the last three digits:
 
:$$P = 2\hspace{0.05cm},\hspace{0.2cm}L = 3\hspace{0.05cm},\hspace{0.2cm}Z = \boldsymbol{\rm A}\hspace{0.05cm}.$$
 
:$$P = 2\hspace{0.05cm},\hspace{0.2cm}L = 3\hspace{0.05cm},\hspace{0.2cm}Z = \boldsymbol{\rm A}\hspace{0.05cm}.$$
  
:<b>2.</b>&nbsp;&nbsp;Richtig sind die <u>beiden ersten Lösungsvorschläge</u>. Der Bindestrich findet sich zum Zeitpunkt <i>i</i> = 5 nicht im Suchpuffer, so dass (0, 0, <b>&ndash;</b>) ausgegeben wird.
 
  
:<b>3.</b>&nbsp;&nbsp;Die folgende Grafik zeigt das <i>Sliding&ndash;Window</i> und die Coderausgabe zu den Zeitpunkten <i>i</i> &#8805; 5. Nach <u><i>i</i> = 9</u> Codierschritten ist der Codiervorgang unter Berücksichtigung von <b>eof</b> beendet.
 
[[File:P_ID2438__Inf_Z_2_3c.png|center|]]
 
  
:<b>4.</b>&nbsp;&nbsp;Bei größerer Puffergröße (<i>G</i> = 5 anstelle von <i>G</i> = 4) ist die Codierung schon nach dem Codierschritt <u><i>i</i> = 6</u> abgeschlossen. Ein Vergleich der beiden Grafiken zeigt, dass sich für <i>G</i> = 5 gegenüber <i>G</i> = 4 nichts ändert bis einschließlich <i>i</i> = 5. Aufgrund des größeren Puffers lässt sich aber nun <b>BAR</b> gemeinsam mit <b>end&ndash;of&ndash;file</b> in einem einzigen Schritt codieren, während mit <i>G</i> = 4 hierfür vier Schritte notwendig waren.
+
'''(2)'''&nbsp;<u>The first two solutions</u> are correct:
[[File:P_ID2439__Inf_Z_2_3d.png|center|]]
+
*The hyphen is not found in the search buffer at time&nbsp; $i = 5$.  
 +
*The output is&nbsp; $(0, 0,$ <b>&ndash;</b>$)$.
  
:<b>5.</b>&nbsp;&nbsp;Ein Nachteil von LZ77 ist das lokale Wörterbuch. Eigentlich schon bekannte Phrasen können nicht für die Datenkomprimierung verwendet werden, wenn sie mehr als <i>G</i> Zeichen vorher im Text aufgetreten sind. Dagegen sind bei LZ78 alle Phrasen im globalen Wörterbuch abgelegt. Richtig ist <u>Aussage 1</u>.
 
  
:Die Aussage 2 trifft dagegen nicht zu.
 
  
:<ul class="liste_ohne"><li>Richtig ist zwar, dass bei LZ78 nur Pärchen (<i>I</i>, <i>Z</i>) übertragen werden müssen, während bei LZ77 jeder Codierschritt durch ein Triple (<i>P</i>, <i>L</i>, <i>Z</i>) gekennzeichnet ist. Das bedeutet aber noch nicht, dass pro Codierschritt auch weniger Bit übertragen werden müssen.
+
'''(3)'''&nbsp; The upper graphic shows the&nbsp; "Sliding Window"&nbsp; and the coder output at times&nbsp; $i>5$.
 +
*After&nbsp; $i = 9$&nbsp; coding steps the coding process is finished considering&nbsp; <b>eof</b>&nbsp; &nbsp; &rArr; &nbsp; $\underline{i_{\rm end} = 9}$.
  
:<ul class="liste_ohne"><li>Betrachten wir beispielhaft die Puffergröße <i>G</i> = 8. Bei LZ77 muss man dann <i>P</i> mit 3 Bit und <i>L</i> mit 4 Bit dargestellen. Berücksichtigen Sie, dass die gefundene Übereinstimmung zwischen Vorschaupuffer und Suchpuffer auch im Vorschaupuffer enden darf.
 
  
:<ul class="liste_ohne"><li>Das neue Zeichen <i>Z</i> benötigt bei LZ78 genau die gleiche Bitanzahl wie bei LZ77 (nämlich 2 Bit), wenn man wie hier vom Symbolumfang <i>M</i> = 4 ausgeht). Die Aussage 2 wäre nur dann richtig, wenn <i>N</i><sub>I</sub> kleiner wäre als <i>N</i><sub>P</sub> + <i>N</i><sub>L</sub>, beispielsweise <i>N</i><sub>I</sub> = 6. Das würde aber bedeuten, dass man die Wörterbuchgröße auf <i>I</i> = 2<sup>6</sup> = 64 begrenzen müsste. Dies reicht für große Dateien nicht aus.
 
  
:<ul class="liste_ohne"><li>Diese Überschlagsrechnung basiert allerdings auf einer einheitlichen Bitanzahl für den Index <i>I</i>. Mit variabler Bitanzahl für den Index kann man etliche Bit einsparen, indem man <i>I</i> nur mit so vielen Bit überträgt, wie es für den Codierschritt <i>i</i> erforderlich ist. Prinzipiell ändert das aber nichts an der Beschränkung der Wörterbuchgröße, was bei großen Dateien stets zu Problemen führen wird.
+
[[File:P_ID2439__Inf_Z_2_3d.png|right|frame|Example of the LZ77 algorithm with&nbsp; $G = 5$]]
 +
'''(4)'''&nbsp; With a larger buffer size&nbsp; $(G = 5$&nbsp; instead of&nbsp; $G = 4)$&nbsp; the coding is already completed after the 6th coding step &nbsp; &rArr; &nbsp; $\underline{i_{\rm end} = 6}$.
 +
*A comparison of the two graphs shows that nothing changes for&nbsp; $G = 5$&nbsp; compared to&nbsp; $G = 4$&nbsp; up to and including&nbsp; $i = 5$&nbsp;.
 +
*Due to the larger buffer, however,&nbsp; "<b>BAR</b>"&nbsp; can now be coded together with&nbsp; "<b>eof</b>"&nbsp; (end-of-file) in a single step, whereas with&nbsp; $G = 4$&nbsp; four steps were necessary for this.
 +
<br clear=all>
 +
'''(5)'''&nbsp;Only <u>statement 1</u> is correct.
 +
*A disadvantage of LZ77 is the local dictionary.&nbsp; Phrases that are actually already known cannot be used for data compression if they occurred more than&nbsp; $G$&nbsp; characters earlier in the text.&nbsp; In contrast, with LZ78 all phrases are stored in the global dictionary.
 +
*It is true that with LZ78 only pairs&nbsp; $(I, \ Z)$&nbsp; have to be transmitted, whereas with LZ77 each coding step is identified by a triple&nbsp; $(P, \ L, \ Z)$&nbsp;.&nbsp; However, this does not mean that fewer bits have to be transmitted per coding step.
 +
*Consider, for example, the buffer size&nbsp; $G = 8$.&nbsp; With LZ77, one must then represent&nbsp; $P$&nbsp; with three bits and&nbsp; $L$&nbsp; with four bits.&nbsp; Please note that the match found between the preview buffer and the search buffer may also end in the preview buffer.
 +
*The new character&nbsp; $Z$&nbsp; requires exactly the same number of bits in LZ78 as in LZ77 (namely two bits), if one assumes the symbol set size&nbsp; $M = 4$&nbsp; as here.
 +
*Statement 2 would only be correct if&nbsp; $N_{\rm I}$&nbsp; were smaller than&nbsp; $N_{\rm P}+ N_{\rm L}$, for example&nbsp; $N_{\rm I} = 6$.&nbsp; But this would mean that one would have to limit the dictionary size to&nbsp; $I = 2^6 = 64$&nbsp;.&nbsp; This is not sufficient for large files.
 +
*Our rough calculation, however, is based on a uniform number of bits for the index&nbsp; $I$.&nbsp; With a variable number of bits for the index, you can save quite a few bits by transmitting&nbsp; $I$&nbsp; only with as many bits as are necessary for the coding step&nbsp; $i$&nbsp;.  
 +
*In principle, however, this does not change the limitation of the dictionary size, which will always lead to problems with large files.
 
{{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 14:10, 10 August 2021

Sliding–Window with  $G = 4$  and  $G = 5$
(valid for "LZ77")

In  Exercise 2.3,  you were supposed to compress  "BARBARA–BAR"  (string of length  $11$, four different characters)  using the LZ78 algorithm. 

In this exercise we use the same text to demonstrate LZ77 compression.  To note:

  • While the successor  "LZ78"  successively builds a global dictionary,  "LZ77"  uses a local dictionary.
  • The LZ77 method works with a  "Sliding Window"  that is gradually shifted over the input text.
  • This  "sliding window"  is divided into the  "preview buffer"  (highlighted in blue in the graphic)  and the  "search buffer"  (highlighted in red).  Both buffers have a size of  $G$  memory locations each.
  • Each coding step  $i$  is characterised by a triple  $(P,\ L,\ Z)$.  Here,  $P$  and  $L$  are integers and  $Z$  is a character.  Transmitted are the binary representations of  $P$,  $L$  and  $Z$.
  • After transmission, the  sliding window  is shifted one or more positions to the right and the next coding step  $i + 1$ begins.


The upper diagram shows the initial allocation with the buffer size  $G = 4$  at the times  $i = 1$  as well as  $i = 4$.

  • At time  $i = 1$ , the search buffer is empty, so the coder output is  $(0, 0,$ B$)$ .
  • After the shift by one position, the search buffer contains a  B, but no string that begins with  A.  The second number triple is therefore  $(0, 0,$ A$)$.
  • The output for  $i = 3$  is  $(0, 0,$ R$)$, since there is no string beginning with  R  in the search buffer even now.


The snapshot at time  $i = 4$  is also shown in the graphic.  The search is now for the character string in the search buffer that best matches the preview text  BARA .  A number triple  $(P,\ L,\ Z)$, is transmitted again, but now with the following meaning:

  • $P$  indicates the position in the (red) search buffer where the match starts.  The  $P$  values of the individual memory locations can be seen in the graphic.
  • $L$  denotes the number of characters in the search buffer that, starting at  $P$,  match the current string in the preview buffer.
  • Finally $Z$  denotes the first character in the preview buffer that differs from the matching string found in the search buffer.


The larger the LZ77 parameter  $G$ , the easier it is to find the longest possible match.  In subtask  (4)  you will notice that the LZ77 encoding with  $G = 5$  gives a better result than the one with  $G = 4$.

  • However, because of the later binary representation of  $P$,  one will always choose  $G$  as a power of two, so that  $G$  can be represented with  $\log_2 \ P$  bits  $(G = 8$   ⇒   three-digit binary number  $P)$.
  • This means that a  "Sliding Window"  with  $G = 5$  has rather little practical relevance.



Hints:


Questions

1

What is the LZ77 output with  $G = 4$  at step  $i = 4$?

$(0, 0,$ B$)$,
$(2, 1,$ A$)$,
$(2, 3,$ A$)$.

2

Which statement is true for the same buffer size  $G = 4$  at step  $i = 5$?

The search buffer contains  "BARA".
The preview buffer says  "–BAR".
The output is  $(0, 0,$ A$)$.

3

After which step  $i_{\rm end}$  is the coding with  $G = 4$  finished?

$i_{\rm end} \ = \ $

4

Now let  $G = 5$.  After which step  $i_{\rm end}$  is the coding finished?

$i_{\rm end} \ = \ $

5

What advantages does LZ78 have over LZ77 for "very large" files?

One finds more often already stored phrases in the dictionary.
Fewer bits have to be transferred per coding step.


Solution

Example of the LZ77 algorithm with  $G = 4$

(1) Solution suggestion 3 is correct.

  • The preview buffer contains the character string  "BARA" at the time  $i = 4$ .
  • The search buffer contains  "BAR" in the last three digits:
$$P = 2\hspace{0.05cm},\hspace{0.2cm}L = 3\hspace{0.05cm},\hspace{0.2cm}Z = \boldsymbol{\rm A}\hspace{0.05cm}.$$


(2) The first two solutions are correct:

  • The hyphen is not found in the search buffer at time  $i = 5$.
  • The output is  $(0, 0,$ $)$.


(3)  The upper graphic shows the  "Sliding Window"  and the coder output at times  $i>5$.

  • After  $i = 9$  coding steps the coding process is finished considering  eof    ⇒   $\underline{i_{\rm end} = 9}$.


Example of the LZ77 algorithm with  $G = 5$

(4)  With a larger buffer size  $(G = 5$  instead of  $G = 4)$  the coding is already completed after the 6th coding step   ⇒   $\underline{i_{\rm end} = 6}$.

  • A comparison of the two graphs shows that nothing changes for  $G = 5$  compared to  $G = 4$  up to and including  $i = 5$ .
  • Due to the larger buffer, however,  "BAR"  can now be coded together with  "eof"  (end-of-file) in a single step, whereas with  $G = 4$  four steps were necessary for this.


(5) Only statement 1 is correct.

  • A disadvantage of LZ77 is the local dictionary.  Phrases that are actually already known cannot be used for data compression if they occurred more than  $G$  characters earlier in the text.  In contrast, with LZ78 all phrases are stored in the global dictionary.
  • It is true that with LZ78 only pairs  $(I, \ Z)$  have to be transmitted, whereas with LZ77 each coding step is identified by a triple  $(P, \ L, \ Z)$ .  However, this does not mean that fewer bits have to be transmitted per coding step.
  • Consider, for example, the buffer size  $G = 8$.  With LZ77, one must then represent  $P$  with three bits and  $L$  with four bits.  Please note that the match found between the preview buffer and the search buffer may also end in the preview buffer.
  • The new character  $Z$  requires exactly the same number of bits in LZ78 as in LZ77 (namely two bits), if one assumes the symbol set size  $M = 4$  as here.
  • Statement 2 would only be correct if  $N_{\rm I}$  were smaller than  $N_{\rm P}+ N_{\rm L}$, for example  $N_{\rm I} = 6$.  But this would mean that one would have to limit the dictionary size to  $I = 2^6 = 64$ .  This is not sufficient for large files.
  • Our rough calculation, however, is based on a uniform number of bits for the index  $I$.  With a variable number of bits for the index, you can save quite a few bits by transmitting  $I$  only with as many bits as are necessary for the coding step  $i$ .
  • In principle, however, this does not change the limitation of the dictionary size, which will always lead to problems with large files.