LZ77 Code
Let xikβ=xiβxi+1ββ¦xkβ,Β Β Β xk=x1kβ=x1βx2ββ¦xkβ - Set the window length to wβN. - A string xn=x1βx2ββ¦xnβ from the finite alphabet X is to be encoded. - Assume that x1ββ¦xiβ1β has already been encoded. - We now find the largest k such that for some j in the range 1β€jβ€w xiβjiβj+kβ1β=xii+kβ1βi.e.Β the longest match of a string of k not-yet-encoded symbols (phrase) with a string starting in the window (search buffer) consisting of the last w symbols xiβwiβ1β=xiβwβxiβw+1ββ¦xiβ1β - Represent the phrase xii+kβ1β with the pair (j,k), i.e.Β the location where the match starts in the window and the length of the match - If no match is found, send xiβ uncompressed. - The encoded phrase is represented by the pointer (F,j,k) or (F,xiβ) where F=1 if a match is found and F=0 if there is no match. Think of j as the number of steps you need to go backwards to find the beginning of the matching phrase and k as the length of the phrase.
There is a prefix code C:Nβ{0,1}β with codeword lengths satisfying β£C(k)β£=logk+2loglogk+O(1)
Assume {Xiβ}=β¦,Xβ1β,X0β,X1β,β¦ is a Stationary & Ergodic Source having entropy rate H~(X). Then the avg code rate of the simplified version of the LZ77 algorithm satisfies nββlimβn1βE[lnβ(Xn)]=nββlimβRΛnβ=H~(X) i.e.Β it is optimal.
LZ78 Code
This method builds an explicit dictionary by incrementally parsing the input sequence into shortest phrases that have not been seen so far. Then we represent each phrase in terms of others that have previously appeared in the form of a pair (i,s) where i is the index of referenced symbol and s and the new symbol added on to the preexisting one.
Example
Our phrase abbaaacbaacbaais parsed as a,b,ba,aa,c,bb,aac,baaand we represent it as (0,a),(0,b),(2,a),(1,a),(0,c),(2,b),(4,c),(3,a) # Properties 1. Code Length: l(Xn)=c(xn)(logc(xn)+O(1))where c(xn) is the number of phrases in the dictionary obtained by parsing xn. 2. Alternative statement for entropy rate nββlimβnE[c(Xn)(logc(Xn)+O(1))]β=H~(X) >[!thm] LZ78 is a Universal Code >The LZ78 algorithm is universal in the class of all stationary and ergodic sources on alphabet X i.e.Β nββlimβnE[c(Xn)(logc(Xn)+O(1))]β=nββlimβE[lnβ(Xn)]=H~(X) for any stationary ergodic source {Xiβ}i=1ββ with entropy rate H~(X).