多媒体技术 || 自适应的霍夫曼编码与原始的霍夫曼编码的比较

第一题:

(a) 自适应的霍夫曼编码与原始的霍夫曼编码相比什么优点:
  1. 原始的Huffman算法给出了一种静态的编码树构造方案,要求在实际编码之前统计被编码对象中符号出现的几率,并据此进行编码树的构造。所以应用此方案时必须对输入符号流进行两遍扫描,而在大多数多媒体应用中数据分布的先前统计数据是不可行的。
  2. 另外,静态编码树构造方案不能对符号流的局部统计规律变化做出反应,因为它从始至终都使用完全不变的编码树。而自适应Huffman编码不需要事先构造Huffman树,而是随着编码的进行,逐步构造Huffman树。同时,这种编码方案对符号的统计也动态进行,随着程序的运行,同一个符号的编码可能发生改变(变得更长或更短)。
  3. 再者就静态编码在储存或传输Huffman编码结果之前,还必须先储存或传输Huffman编码树,自适应霍夫曼编码则不需要,这大大节省了内存开销。
(b)
(i)接收到的后续几个字母是什么

接收到的后续的几个字母分别是 b(01) a(01) c(00 10) c(101)

(推导过程同第二问)

(ii)画出接收每一个后续字母后的自适应霍夫曼树

在这里插入图片描述fig 1

在这里插入图片描述fig 2

在这里插入图片描述fig 3

在这里插入图片描述fig 4

推导过程:

步骤字符分析
01从7-11图定位到01为b,然后b的权值+1,此时b的节点权值变为3>a(2),b与a交换位置,huffman树变为fig1
01从fig1定位到01为a,然后a权值+1,此时a的节点权值变为3=b(3),树的节点不做变动,huffman树变为fig2
00 10根据fig2定位到00是new,意味着有新字符的加入,然后根据下面的10知道新加入的字符是c,然后用包含c和new的子树替换旧的new节点,然后将a的父节点的权值+1变为4>b(3),与b交换位置,得到fig3
101根据fig3定位到c,然后将相应的节点权值分别+1,发现没有需要置换的节点和子树,得到fig4
  • 3
    点赞
  • 16
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
自适应霍夫曼编码的C++版本简单实现 class AdaptiveTree { public: AdaptiveTree(int rootNum); AdaptiveTree(int rootNum, string str); void swap(int first, int second); // swap two nodes of the tree void initalCode(); // initializing the data string char2code(unsigned char letter); // locate the character in the tree with its corresponding binary string and return the string string char2binary(unsigned char letter); // translating the character to the 8-bit binary string unsigned char binary2char(string bin); // translating the binary string: bin to the corresponding character int spawn(unsigned char letter); // add a new character to the original tree void updateTree(unsigned char newchar); // update the tree int highestInBlock(int count); // return the highest node to be exchanged void setString(string str); // string decodingStr() const; void encoding(); string decoding(); unsigned char code2char(string bincode); static int size(); string binStr() const; // return the binary string of string: tempString private: void run(); int findchar(unsigned char letter ); // locate the letter in the tree string tempString; //temp string to be encoded needed to be stored here string deStr;// used for storing the decoding string string bin; // used for storing the result of encoding process /* Adaptive Tree data members */ HuffmanTree *tree; int root; /* Adaptive Tree constants */ static int ALPH_SIZE; // size of the alphabet static unsigned char none; // not a unsigned character static unsigned char NYT; // Not Yet transmitted code };

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值