How to determine letter boundaries in Huffman encoded strings?
Huffman codes are prefix-free codes (no codeword is a prefix of another), and so they are uniquely decodable. That means that if you encode a message using a Huffman code, then there is no other message that results in the same encoding. 

Here is why. Suppose that $w$ is some binary string. We will show that $w$ encodes at most one message, in the Huffman code $\{c_1,\ldots,c_n\}$. Let's try to factor $w$ as $w = c_i w'$. I claim that this can be done in at most one way. Otherwise, we would have $w = c_i w' = c_j w''$, and so either $c_i$ is a prefix of $c_j$ or the other way around. If there is no such factorization, then $w$ encodes no message. Otherwise, suppose $w = c_i w'$. Then the first character of the message (if there is any) is $i$, and the rest is encoded by $w'$.

Prefix-free codes can be decoded very efficiently: to find the prefix $c_i$ alluded to in the preceding paragraph, just follow the Huffman tree until you get to a leaf. There is no look-ahead. There is a more general class of codes, uniquely decodable codes, which are codes satisfying what we proved in the last paragraph: every string is the encoding of at most one message. Such codes could require arbitrary large look ahead: consider for example $\{00,10,1\}$ and a word $1 w^n$. If $n$ is even then this is broken up $1(00)^{n/2}$, if $n$ is odd then $10(00)^{(n-1)/2}$. In order to tell which is which, we need to look ahead to the end of the string.

Given that prefix-free codes are easier to decode, but uniquely decodable codes are more general, you could ask: do we gain something by allowing uniquely decodable codes which are not prefix-free? This is answered by the Kraft&ndash;McMillan inequality: every uniquely decodable code $\{c_1,\ldots,c_n\}$ satisfies
$$ \sum_{i=1}^n 2^{-|c_i|} \leq 1, $$
and conversely every set of codeword lengths satisfying this inequality correspond to some prefix-free code. So prefix-free codes are as general as it gets.



The proof is not too difficult. Suppose $c_1,\ldots,c_n$ is uniquely decodable, with maximum codeword length $M$. Consider the encodings of all words of length $\ell$. Weight each encoding $x$ by $2^{-|x|}$, and sum. You get
$$ \left(\sum_{i=1}^n 2^{-c_i}\right)^\ell. $$
On the other hand, since the code is uniquely decodable, for each possible length, $2^{-|x|}$ must sum to at most $1$. Since words of length $\ell$ are encoded by strings of length at most $M\ell$, we conclude
$$ \left(\sum_{i=1}^n 2^{-c_i}\right)^\ell \leq M\ell. $$
Taking $\ell$th roots and letting $\ell \to \infty$, we recover the inequality.

For the other direction, suppose that the integers $\ell_1,\ldots,\ell_n$ satisfy $\sum_{i=1}^n 2^{-\ell_i} \leq 1$. Without loss of generality, we can assume that the sum is exactly $1$: otherwise, suppose that the sum is $A/2^B$ (for integer $A$), and add $2^B-A$ new integers equal to $B$.

I claim that either $n = 1$ or there must be a subset of these summing to exactly $1/2$. Indeed, suppose $n &gt; 1$, and arrange all weights in non-decreasing order $\ell_1 \leq \dots \leq \ell_n$, and look at the running sums $2^{-\ell_1} + \dots + 2^{-\ell_i}$. There must be a first index at which they cross $1/2$, say $2^{-\ell_1} + \dots + 2^{-\ell_i} \geq 1/2$ but $2^{-\ell_1} + \dots + 2^{-\ell_{i-1}} &lt; 1/2$. Write the latter sum as $S = A/2^B$, where $B \leq \ell_{i-1} \leq \ell_i$ and $A &lt; 2^{B-1}$. Then $S + 2^{-\ell_i} = (A + 2^{B-\ell_i})/2^B \geq 1/2$, so $A + 2^{B-\ell_i} \geq 2^{B-1}$. Since $2^{B-\ell_i} \leq 1$, we must have $2^{B-\ell_i} = 1$ and $A + 2^{B-\ell_i} = 2^{B-1}$, so $S + 2^{-\ell_i} = 1/2$.

When $n = 1$, the code $\{\epsilon\}$ is a prefix-free code with codeword lengths $0$. For $n &gt; 1$, divide the weights into two sets $L_0,L_1$ such that $\sum_{i \in L_0} 2^{-\ell_i} = \sum_{i \in L_1} 2^{-\ell_i}$. Construct two prefix-free codes $C_0,C_1$ from the lengths obtained by subtracting $1$ from all weights in $L_0,L_1$, respectively. Now glue these codes together by prefixing $C_0$ by $0$ and $C_1$ by $1$.