PDA

View Full Version : sort 4 elements with 3 comparisons (not a homework question)


Mihail121
01-17-2009, 07:55 AM
Now I've had a friend over telling me one could sort 4 elements (balls for ex.) using 3 measurments with a standard scale. I tried and tried and TRIED but I just can't do it. Does anyone have an idea how would it be possible?

Nils Pipenbrinck
01-17-2009, 10:43 AM
It's not possible. The minimum number of compare and swap-operations you need is five (assuming the data is not already partly sorted).

Sol_HSA
01-17-2009, 12:46 PM
Depends on how you define measurements. spaghetti sort (http://en.wikipedia.org/wiki/Spaghetti_sort) could definitely do it.. =)