Data Structures & AlgorithmsHardTCS NQT · greedy coding
Problem: Which property must hold for Huffman coding to produce an optimal prefix code?
- A. All frequencies must be equal
- B. Merging the two least-frequent symbols first is always part of some optimal tree (exchange argument)
- C. The alphabet must be binary numbers
- D. The code must be fixed-length
Correct answer: B. Merging the two least-frequent symbols first is always part of some optimal tree (exchange argument)
An exchange argument shows that the two rarest symbols can be placed as siblings at the deepest level of an optimal tree.
More Coding Interview Problems questions
- Problem: What is the complexity of Kruskal's algorithm when edges are already sorted and union-find uses path compression and union by rank?
- Problem: What does the Kuhn-Munkres (Hungarian) algorithm compute on a bipartite graph with weights?
- Problem: Which approach computes the number of distinct substrings of a string of length n in O(n log n) with a suffix array?
- Problem: Which graph algorithm checks whether a directed graph is a DAG in O(V + E)?
- Problem: What is the expected number of comparisons for a binary search on a sorted array of n = 1000 elements (successful search, worst…
- Problem: What is the time complexity of finding the articulation points and bridges together with one DFS?