Huffman (C,f) (1) n = |C| (2) foreach c in C (3) L.PushBack(c) (4) for i= 1 to n-1 (5) z = newnode (6) z.leftchild = ExtractMin(L) (7) z.rightchild = ExtractMin(L) (8) f(z) = f(z.leftchild) + f(z.rightchild) (9) L.PushBack(z)
The timing really depends on the cost of inserting into the list and extracting the min from the list (6,7,9) With a list these are all O(n), and the outer loop makes this an O(n2) Algorithm.