7、使用LZ77算法对一个序列进行编码。给定C(a)=1,C(p)=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.对解码所得到的序列进行编码,确保得到相同的三元组序列。
解:窗口大小为20,前向缓冲区大小为10,搜索窗口大小10。
C(a) = 1, C( ) = 2, C(r) = 3, C(t) = 4
解码过程:
输入 输出:
<0, 0, 3> r
<0, 0, 1> ra
<0, 0, 4> rat
<2, 8, 2> ratatatatat
<3, 1, 2> ratatatatat a
<0, 0, 3> ratatatatat a r
<6, 4, 4> ratatatatat a rat at
<9, 5, 4> ratatatatat a rat at a rat
编码过程:输入序列:ratatatatat a rat at a rat
输入 输出:
||ratatatatat a rat at a rat <0, 0, 3>
|r|atatatatat a rat at a rat <0, 0, 1>
|ra|tatatatat a rat at a rat <0, 0, 4>
|rat|atatatat a rat at a rat <2, 8, 2>
ra|tatatatat |a rat at a rat <3, 1, 2>
rata|tatatat a |rat at a rat <0, 0, 3>
ratat|atatat a r|at at a rat <6, 4, 4>
ratatatata|t a rat at|a rat <9, 5, 4>
编码输出的三元组与解码输入的三元组完全一样。
8、给定以下初始词典和接收序列,构建一个LZW词典,并对所发送的序列进行解码。
接收序列:4,5,3,1,2,8,2,7,9,7,4
初始词典:
索引 |
项 |
1 |
S |
2 |
P |
3 |
I |
4 |
T |
5 |
H |
接收到的序列:4, 5, 3, 1, 2, 8, 2, 7, 9, 7, 4
输入: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
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 |
15 |
HIT |