对于我的项目,我必须创建一个huffman树项目,但我的讲师说我不能使用优先级队列来构建它?但我不知道该怎么做。还有其他方法可以不用优先级队列来创建huffman树吗?
发布于 2022-11-17 12:24:13
在实践中,有一个经常被用来建造赫夫曼树的技巧:
1. Remove the two smallest symbols from the beginnings of two lists
2. Combine them and add them to the end of the combined list. Because the new symbol has a higher combined probability than any combined symbol created before, this list remains sorted.在初始排序之后,最小的概率符号总是两个列表中的第一个,因此不需要优先级队列或搜索就可以找到它。
这种技巧相当聪明,而且你的讲师也不会指望你自己去想它,所以它很可能是在课堂上教或引用的。
https://stackoverflow.com/questions/74464025
复制相似问题