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.对解码所得到的序列进行编码,确保得到相同的三元组序列。
解:(1)由于C(a)=1,C(b)=2,C(r)=3,C(t)=4,所以解码的结果如下:
序列 |
输出 |
<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 |
(2)编码:由于窗口的大小为20,先进性缓冲区的大小为10,则编码缓冲区的大小为10
开始解码序列为:ratatatatatbabratbatbabrat
输入序列为: l ratatatatatbabratbatbabrat 没有与r匹配的项 则输出三元组为:<0,0,3>
输入序列为:r l atatatatatbabratbatbabrat 没有与a匹配的项 则输出三元组为:<0,0,1>
输入序列为:ra l tatatatatbabratbatbabrat 没有与t匹配的项 则输出三元组为:<0,0,4>
解:
由于接收序列为:4,5,3,1,2,8,2,7,9,7,4;
所以输入序列为: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 |