第四次作业
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> | 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
解码出的序列: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
解码的序列为:THIS
1 | 5 |
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 IS
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 HI
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 HIS_
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
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 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 |
所以解码的序列为THIS IS HIS HIT