How to prove that for a full (each node that's not a leaf has 2 nodes) binary tree $T$ of $n$ leaves there's a series of frequencies $f_1,f_2,...,f_n$ such that if we use Huffman algorithm on the series we'll get $T$?
First in order to get frequencies from $T$ we can assign the probability of $\frac{1}{2^d}$ to each node where $d$ is the depth of a given node. The root node will have the probability of $1$ which means $100$%. After one traversal of $T$ we could fill the array with the frequencies of the leaves of $T$ (only leaves correspond to the the actual values to be encoded).
I'm not sure how to prove that if we apply Huffman algorithm to the frequencies one of the trees will happen to be $T$. It seems like if we build a tree from the frequencies each time such that the new tree is different (if possible) from the previous tree we'll eventually build $T$. Also we know that Huffman tree is always a full tree.
The Huffman algorithm is as follows (as described in Algorithm Design by Jon Kleinberg, Eva Tardos):
Huffman(S) {
if |S|=2 {
return tree with root and 2 leaves
} else {
let y and z be lowest-frequency letters in S
S’ = S
remove y and z from S’
insert new letter ω in S’ with f_ω=f_y+f_z
T’ = Huffman(S’)
T=add two children y and z to leaf ω from T’
return T
}
}