参考书《数据压缩导论(第4版)》 Page 121
7、使用LZ77算法对一个序列进行编码。给定C(a)=1,C(b)=2,C(r)=3,C(t)=4.对以下三元组序列进行解码:
<0,0,3><0,0,1><0,0,4><2,8,2><3,1,2><0,0,3><6,4,4><9,5,4>
假定窗口的大小为20,先行缓冲区的大小为10.对解码所得到的序列进行编码,确保得到相同的三元组序列。
解:解码过程:
输入 输出
<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
编码过程:
输入序列:ratatatatatbabratbatbabrat
输入 输出
||ratatatatatbabratbatbabrat <0,0,3>
|r|atatatatatbabratbatbabrat <0,0,1>
|ra|tatatatatbabratbatbabrat <0,0,4>
|rat|atatatatbabratbatbabrat <2,8,2>
r|atatatatatb|abratbatbabrat <3,1,2>
rat|atatatatbab|ratbatbabrat <0,0,3>
ratat|atatatbabr|atbatbabrat <6,4,4>
ratatatata|tbabratbat|babrat <9,5,4>
编码输出的三元组与解码输入的三元组完全相同。
8、给定以下初始词典和接收序列,构建一个LZW词典,并对所发送的序列进行解码。
接收序列:4,5,3,1,2,8,2,7,9,7,4
初始词典:
索引 | 项 |
1 | S |
2 | b |
3 | I |
4 | T |
5 | H |
解:
输入:4,5,3,1,2,8,2,7,9,7,4 解码得到的序列:T
字典:
1 | S |
2 | |
3 | I |
4 | T |
5 | H |
输入:4,5,3,1,2,8,2,7,9,7,4 解码得到的序列:TH
字典:
1 | S |
2 | |
3 | I |
4 | T |
5 | H |
6 | TH |
输入:4,5,3,1,2,8,2,7,9,7,4 解码得到的序列:THI
字典:
1 | S |
2 | |
3 | I |
4 | T |
5 | H |
6 | TH |
7 | HI |
输入:4,5,3,1,2,8,2,7,9,7,4 解码得到的序列:THIS
字典:
1 | S |
2 | |
3 | I |
4 | T |
5 | H |
6 | TH |
7 | HI |
8 | IS |
输入:4,5,3,1,2,8,2,7,9,7,4 解码得到的序列:THIS
字典:
1 | S |
2 | |
3 | I |
4 | T |
5 | H |
6 | TH |
7 | HI |
8 | IS |
9 | S |
输入:4,5,3,1,2,8,2,7,9,7,4 解码得到的序列:THIS IS
字典:
1 | S |
2 | |
3 | I |
4 | T |
5 | H |
6 | TH |
7 | HI |
8 | IS |
9 | S |
10 | I |
输入:4,5,3,1,2,8,2,7,9,7,4 解码得到的序列:THIS IS
字典:
1 | S |
2 | |
3 | I |
4 | T |
5 | H |
6 | TH |
7 | HI |
8 | IS |
9 | S |
10 | I |
11 | IS |
输入:4,5,3,1,2,8,2,7,9,7,4 解码得到的序列:THIS IS HI
字典:
1 | S |
2 | |
3 | I |
4 | T |
5 | H |
6 | TH |
7 | HI |
8 | IS |
9 | S |
10 | I |
11 | IS |
12 | H |
输入:4,5,3,1,2,8,2,7,9,7,4 解码得到的序列:THIS IS HIS_
字典:
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 |
输入:4,5,3,1,2,8,2,7,9,7,4 解码得到的序列:THIS IS HIS HI
字典:
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 | S H |
输入:4,5,3,1,2,8,2,7,9,7,4 解码得到的序列:THIS IS HIS HIT