1
votes

I am little confuse whether huffman algorithm uses priority queue or sorted queue to build huffman tree? For example: https://www.geeksforgeeks.org/greedy-algorithms-set-3-huffman-coding/.

In the above link they are saying that use minimum heap but as i can see they have just used sorted list to make huffman tree.Please correct me if I am wrong.

1

1 Answers

2
votes

A minheap is used to create a priority queue which is a form of a sorted queue. And yes, any sorted data structure can be used to help create a huffman code; however, a heap is traditionally used because the huffman tree is basically a specialized construction of a max heap.