Given string: $abbccddeee$
$a$ has the least frequency and should be the leaf of the tree. $b,c$ and $d$ have the same frequency but as per Condition 2 in the questions $d$ should be taken first, followed by $c$ and then $b.$ $e$ has the highest frequency and so must be taken last.
$\begin{array}{|c|c|} \hline \textbf{Alphabet} & \textbf{Frequency} \\\hline a & 1 \\\hline b & 2 \\\hline c & 2 \\\hline d & 2 \\\hline e & 3 \\\hline \end{array}$
The final Huffman tree looks like:
$\begin{array}{|c|c|} \hline \textbf{Prefix Code} & \textbf{Code Length} \\\hline a = 000 & 3 \\\hline b =10 & 2 \\\hline c = 11 & 2 \\\hline d = 001 & 3 \\\hline e = 01 & 2 \\\hline \end{array}$
$\therefore$ Minimum length of encoded string: $(1*3)+(2*2)+(2*2)+(3*2)+(2*3)=23$
Option $B$ is correct.
References:
- GATE 2007
- GATE 2017
- Huffman_coding wiki