知识卡片
霍夫曼堆实现复杂度
- 用二叉最小堆维护频率时,建堆需O(n);
- 随后n−1轮各做取最小与插入,每轮O(lg n),总时间O(n lg n)。
该界依赖堆实现,不能脱离数据结构直接断言。
这张卡片看不懂?
这张卡片已通过人工审查,不再接受失败反馈。
已有反馈 · 0 条
还没有人提交反馈。
在整书笔记中的位置
原书出处 · 1 处
- 第15章 贪心算法 · 查看原书依据
For a set C of n characters, the BUILD-MIN-HEAP procedure discussed in Section 6.3 can initialize Q in line 2 in O(n) time. The for loop in lines 3–10 executes exactly n − 1 times, and since each heap operation runs in O(lg n) time, the loop contributes O(n lg n) to the running time. Thus, the total running time of HUFFMAN on a set of n characters is O(n lg n).
参考来源
- 位置:《算法导论(第4版)》第15章《贪心算法》(OEBPS/chapter015.xhtml,文本字符[40000,45000))。
- 结论依据:15.3 节先限定 Q 用二叉最小堆,BUILD-MIN-HEAP 为 O(n),随后 n−1 轮的堆操作各 O(log n),总计 O(n log n)。
- 原始内容:For a set C of n characters, the B UILD -M IN -H EAP procedure discussed in Section 6.3 can initialize Q in line 2 in O ( n ) time. The for loop in lines 3–10 executes exactly n − 1 times, and since each heap operation runs in O (lg n ) time, the loop contributes O ( n lg n ) to the running time. Thus, the total running time of H UFFMAN on a set of n characters is O ( n lg n ).