Reference exercises:
7. Encode a sequence using the LZ77 algorithm. Given C (a) =1,c (b) =2,c (R) =3,c (t) = 5, the ternary sequence is decoded:
<0,0,3><0,0,1><0,0,4><2,8,2><3,1,2><0,0,3><6,4,4><9,5,4>
Assume that the size of the window is 20, the size of the antecedent buffer is 10. Encode the sequence obtained by decoding to ensure that the same ternary sequence is obtained.
Solution:
Sequence |
Output |
<0,0,3> |
R |
<0,0,1> |
Ra |
<0,0,4> |
Rat |
<2,8,2> |
Ratatatatatb |
<3,1,2> |
Ratatatatatbab |
<0,0,3> |
Ratatatatatbabr |
<6,4,4,> |
Ratatatatatbabratbat |
<9,5,4> |
Ratatatatatbabratbatbabrat
|
Encoding process:
Input sequence: Rat Atatatatbabratbatbabrat
Input |
Output |
R _atatatatatbabratbatbabrat |
<0,0,3> |
Ra_ Tatatatatbabratbatbabrat |
<0,0,1> |
Rat _ Atatatatbabratbatbabrat |
<0,0,4> |
R _atatatatatb_ Abratbatbabrat |
<2,8,2> |
Rat_ Atatatatba _ Bratbatbabrat |
<3,1,2> |
Rata _ tatatatbab _ Ratbatbabrat |
<0,0,3> |
Ratatatatatbabratbatbabrat |
<6,4,4,> |
Ratatatatatbabratbatbabrat |
<9,5,4>
|
8. Given the following initial dictionaries and acceptance sequences, construct an LZW dictionary and decode the multiple sent sequences. Acceptance sequence: 4,5,3,1,2,8,2,7,9,7,4
Initial dictionary:
| Index |
Item |
| 1 |
S |
| 2 |
P |
| 3 |
I |
| 4 |
T |
| 5 |
H |
Solution:
1) Input 4,5,3,1,2,8,2,7,9,7,4
| Index |
Entry |
| 1 |
S |
| 2 |
_ |
| 3 |
I |
| 4 |
T |
| 5 |
H |
The decoded sequence is: T
2) Input 4,5,3,1,2,8,2,7,9,7,4
| Index |
Entry |
| 1 |
S |
| 2 |
- |
| 3 |
I |
| 4 |
T |
| 5 |
H |
The decoded sequence is: TH
3) Input 4,5,3,1,2,8,2,7,9,7,4
| Index |
Entry |
| 1 |
S |
| 2 |
_ |
| 3 |
I |
| 4 |
T |
| 5 |
H |
| 6 |
TH |
The decoded sequence is: THI
10) Input 4,5,3,1,2,8,2,7,9,7,4
| Index |
Entry |
| 1 |
S |
| 2 |
_ |
| 3 |
I |
| 4 |
T |
| 5 |
H |
| 6 |
TH |
| 7 |
Hi |
| 8 |
Is |
| 9 |
S_ |
| 10 |
_i |
| 11 |
Is_ |
| 12 |
_h |
| 13 |
His |
The decoded sequence is: The is the his HI
11) Input 4,5,3,1,2,8,2,7,9,7,4
| Index |
Entry |
| 1 |
S |
| 2 |
_ |
| 3 |
I |
| 4 |
T |
| 5 |
H |
| 6 |
TH |
| 7 |
Hi |
| 8 |
Is |
| 9 |
S_ |
| 10 |
_i |
| 11 |
Is_ |
| 12 |
_h |
| 13 |
His |
| 14 |
R_i |
The decoded sequence is:
The last decoding sequence is:
Feng Juan's fourth time assignment