Similar questions 1 more →
Greedy Algorithms

Answer & solution
Official answer: 358
1. Set up the reasoning. A merge of lengths a and b needs a+b-1 comparisons in the worst case. The optimal merge-pattern rule repeatedly joins the two currently shortest sequences, reinserting the combined length.
2. Derive the result. Optimal merging repeatedly combines the two shortest lists: 20+24=44, 30+35=65, 44+50=94, 65+94=159. A merge of lengths a, b uses at most a+b−1 comparisons, so total 43+64+93+158=358. The shortest-pair rule minimizes weighted leaf depth, as in Huffman coding.
3. Check the interpretation. Track lengths after each merge: 44 joins the queue after 20 and 24; 65 after 30 and 35; then combine 44 and 50. Subtract one comparison for each of the four merges, not just once from the final length.