I'm reading James Anderson's Automata Theory with Modern Applications. Here:
And I tried to prove the following theorem (for prefix codes).
I tried in the following way: Suppose $C$ is a prefix code which is not uniquely decipherable, that is there is a string $u \in C$ with two different expressions $u=ab=cd$. But $u=vw$ and hence $vw=ab=cd$ where $w= \lambda$ and $\lambda$ is the empty word, therefore $v=a=c$ and $\lambda=b=d$ which contradicts your hypothesis that $u$ is not uniquely decipherable.
Is this correct? I am confused because I paired $v=a=c$ and $\lambda=b=d$ and I'm not sure if that is valid.



It might be easier to do an inductive proof on the number of code symbols in two words.
Suppose $C$ is a prefix code for $S$.
I use $|s|$ for the length (in terms of $\Sigma$) of $s$.
Choose $s \in S$ and write $s=c_1 t_1 = c_2 t_2$ where $c_k \in C$ and $t_k \in C^*$. Suppose $|c_1| \le |c_2|$ and write $s= c_1 w t_1'$, where $|w| = |c_2|-|c_1|$ and $t_1 = w t_1'$. Then $c_1w = c_2$ and hence $c_1 = c_2$ and $w = \lambda$. Now repeat with $t_1, t_2$.