- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
What is an optimal Huffman code for the following characters whose frequencies are the first 8 Fibonacci numbers: a : 1, b : 1, c : 2, d : 3, e : 5, f : 8, g : 13, h : 21? Generalize the case to find an optimal code when the frequencies are the first n Fibonacci numbers.
这是我遇到的作业问题之一。我不是要直接回答,只是为了一些资源。
我应该在哪里寻找拼凑来回答问题?
最佳答案
霍夫曼编码算法取两个频率最低的节点并将它们连接起来形成一个父节点,该父节点的子节点频率之和相等。在符号的随机频率中,我们每次都需要计算最少的两个节点进行组合,但是在斐波那契频率序列的情况下,斐波那契序列中的序列与霍夫曼编码中的序列相同。
例子:-a:1,b:1,c:2,d:3,e:5,f:8,g:13,h:21
它将形成一个左偏或右偏的树,其中每个符号的编码可以使用简单的公式导出
如果n不是符号
a = (n-2)*0 + 0
b = (n-2)*0 + 1
c = (n-3)*0 + 1
d = (n-4)*0 + 1
e = (n-5)*0 + 1
...最后 = 1
所以对于上面的例子
a = (n-2)*0 + 0 = (6)*0 + 0 = 0000000
b = (6)*0 + 1 = 0000001
c = (5)*0 + 1 = 000001
.......
我希望你能找到模式
有趣的是平均位长的计算
avg = ((n-1)*2 + sumof((n-i+1)*fib(i)) 其中 i 在 (3,n))/(sumof(fib(i)) 其中 i 在(1,n))
以上可化简为直接公式。
关于algorithm - 斐波那契数的最佳霍夫曼代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19883086/
已关闭。此问题需要 debugging details 。目前不接受答案。 编辑问题以包含 desired behavior, a specific problem or error, and the
我这样定义了一个二叉树: struct btree { int x; btree* left_child = nullptr; btree* right_child = nul
我有这个霍夫曼代码,旨在返回数组中每个字母的霍夫曼代码并按字母顺序打印它们。问题是它不生成任何输出,而是继续处理,直到我手动退出它。谁能帮我找出错误吗?我认为我的代码是正确的,但我不知道无限循环从何而
动机 想象一下一个哈夫曼压缩文件被部分下载,就像在p2p软件中一样,所以我们首先为整个文件分配磁盘空间,然后开始随机下载文件块。其中一个哈夫曼密码(但我们不知道是哪一个)是一个结束密码,所以如果这个密
以下 block 由霍夫曼 block 标记嵌套 -HUFF---------------------------------------------------------------------0
我是一名优秀的程序员,十分优秀!