What is the time complexity of Huffman Coding?
(A) O(N)
(B) O(NlogN)
(C) O(N(logN)^2)
(D) O(N^2)
Answer: (B)
Explanation: O(nlogn) where n is the number of unique characters. If there are n nodes, extractMin() is called 2*(n – 1) times. extractMin() takes O(logn) time as it calles minHeapify(). So, overall complexity is O(nlogn).
See here for more details of the algorithm.
Quiz of this Question
Recommended Posts:
- Algorithms Quiz | Greedy Algorithms | Question 8
- Algorithms | Greedy Algorithms | Question 1
- Algorithms | Greedy Algorithms | Question 6
- Algorithms | Greedy Algorithms | Question 5
- Algorithms | Greedy Algorithms | Question 4
- Algorithms | Greedy Algorithms | Question 7
- Algorithms | Greedy Algorithms | Question 3
- Algorithms | Analysis of Algorithms (Recurrences) | Question 4
- Algorithms | Analysis of Algorithms (Recurrences) | Question 11
- Algorithms | Analysis of Algorithms (Recurrences) | Question 11
- Algorithms | Analysis of Algorithms (Recurrences) | Question 9
- Algorithms | Analysis of Algorithms (Recurrences) | Question 3
- Algorithms | Analysis of Algorithms (Recurrences) | Question 11
- Algorithms | Analysis of Algorithms (Recurrences) | Question 1
- Algorithms | Analysis of Algorithms (Recurrences) | Question 6
- Algorithms | Analysis of Algorithms (Recurrences) | Question 8
- Algorithms | Analysis of Algorithms (Recurrences) | Question 2
- Algorithms | Analysis of Algorithms (Recurrences) | Question 7
- Algorithms | Analysis of Algorithms | Question 14
- Algorithms Quiz | Bit Algorithms | Question 4

