Huffman Tree¶
Source code: src/pydsadoc/_tree/huffman.py
- class MinHeap(*args, **kwargs)¶
Implementation of the minimum heap with sequential list.
- heapify(arr: list[HNode], /) None¶
Make heap from list in a more efficient way.
It’s also called Floyd Algorithm, which is quicker than pushing items one by one. Time complexity is \(O(n)\).
- heappop() HNode¶
Remove and return smallest item from the heap.
Time complexity is \(O(\log n)\).
The Priority Queue
The Huffman Tree can be built in an optimal way by using priority queue.
The priority queue is implemented with minimum heap here, namely the class
MinHeap described above.