Design an efficient algorithm to sort 5 distinct keys in fewer than 8 comparisons

Compare A to B and C to D. WLOG, suppose A>B and C>D.
Compare A to C. WLOG, suppose A>C.
Sort E into A-C-D. This can be done with two comparisons.
Sort B into {E,C,D}. This can be done with two comparisons, for a total of seven.

Leave a Comment