Searching, Sorting & Selection


Answer & solution
Answer: 7 in the optimal worst case (no official key was published)
There are 5!=120 possible strict orders, and a binary comparison tree of height six distinguishes at most 64 outcomes. Thus at least seven comparisons are necessary in the worst case. For sufficiency, sort two pairs (two comparisons), compare their larger elements (one), and rename them so a≤b≤d with c≤d. Insert the fifth key into a, b, d in at most two comparisons. Insert c into the prefix preceding d: at most three elements precede d, giving at most four possible positions and two further comparisons. Total: seven. This is a worst-case guarantee; a best-case successful path can be shorter.