Huffman Codes Flashcards

1
Q

Are Huffman trees unique for a given frequency table? Is it possible to generate a different tree from this same table of frequencies that is also optimal?

A

No, the right and left subtrees are arbitrary. For ex, we can switch a and b below

   (1)
/      \   a        b
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Huffman Algorithm, runtime, and improvenment

A

T(n) = T(n-1) + 2*findmin

We have to find the minimum freq at each level for all letters, so this ends up being an N^2 algorithm.

However, employing a min heap, which is build in O(n) using Floyd’s method, and also gives us the minimum frequency with fix-up of O(logn). Then, the overall method becomes O(nlogn).

Details (not mandatory)

Huffman(S):
if |S| = 2:
return a tree with root and two leaves
ELSE:
(u, v) = find two min frequency chars in S
S = S - (u, v)
S = S + new char W which is fu + fv
T’ = Huffman(S)
T = T’ with leaf ω removed and replaced with interior node +two children, u and v; label left branch 0, right branch 1return T

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Fixed length vs Variable length encoding

A

Fixed length is wasteful and there’s no even frequency distribution

Variable-length encoding is better and avoids ambiguity by using prefix-free variable-length encoding.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Read Huffman proof of correctness

A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly