Source: Internet newsgroup rec.puzzles.
First, use 3 weighings to sort 3 of the weights. Next, weigh the median weight against each of the two remaining weights. If the median weight is heavier than both or lighter than both, then use three weighings to sort the three unsorted weights. If the median weight is heavier than one but lighter than the other, then use two weighings to sort each of the two unsorted pairs.
E>C, E>A, B>C EABCD E>C, E>A, C>B, B>D EACBD E>C, E>A, C>B, D>B EACDB E>C, A>E, B>C, B>E ABECD E>C, A>E, B>C, E>B AEBCD E>C, A>E, C>B, B>D AECBD E>C, A>E, C>B, D>B AECDB C>E, E>D, B>E, B>C ABCED C>E, E>D, B>E, C>B ACBED C>E, E>D, E>B, B>D ACEBD C>E, E>D, E>B, D>B ACEDB C>E, D>E, B>D, B>C ABCDE C>E, D>E, B>D, C>B ACBDE C>E, D>E, D>B, B>E ACDBE C>E, D>E, D>B, E>B ACDEB
Hmm, I knew that a process using 7 weighings was theoretically possible, since
7 weighings can distinguish among 2^7 = 128 possibilities, more than the 120
possible permutations. However, I didn't really expect for such a process
to exist. I guess I should have looked more closely.
Call the weights A, B, C, D, and E. Weigh A against B. WLOG, suppose A is
lighter than B. It is clear that our next weighing cannot include either A
or B, because if, say, A is lighter than C, then there remain 2 (of 6)
possible orderings of A, B, and C, leaving 40 (120*2/6) possible orderings
of A, B, C, D, and E - more than we can handle with 5 weighings. Therefore,
weigh C against D. WLOG, suppose C is lighter than D. Actually, for the
sake of clarity, let me at this point revert to an outline form:
1) A weighs in lighter than B.
2) C weighs in lighter than D.
3) WLOG, A weighs in lighter than C.
4) Weigh C against E.
5) If C is lighter, weigh D against E.
6) If D is lighter, weigh B against D
7) If B is lighter, weigh B against C.
a) If B is lighter, ABCDE.
b) If C is lighter, ACBDE.
7) If D is lighter, weigh B against E.
a) If B is lighter, ACDBE.
b) If E is lighter, ACDEB.
6) If E is lighter, weigh B against E.
7) If B is lighter, weigh B against C.
a) If B is lighter, ABCED.
b) If C is lighter, ACBED.
7) If E is lighter, weigh B against D.
a) If B is lighter, ACEBD.
b) If D is lighter, ACEDB.
5) If E is lighter, weigh A against E.
6) If A is lighter, weigh B against C.
7) If B is lighter, weigh B against E.
a) If B is lighter, ABECD.
b) If E is lighter, AEBCD.
7) If C is lighter, weigh B against D.
a) If B is lighter, AECBD.
b) If D is lighter, AECDB.
6) If E is lighter, weigh B against D.
7) If B is lighter, weigh B against C.
a) If B is lighter, EABCD.
b) If C is lighter, EACBD.
7) If D is lighter, EACDB.
Given the complexity of the above process, it seems impossible to determine
a formula for how many weighings are necessary to sort n weights. A decent
upper bound is (n(k+1) - 2^(k+1) + 1), where 2^k < n <= 2^(k+1). Or to make
it more intuitive, 2^k(k-1) + 1 is an upper bound for 2^k weights. We can
get this upper bound inductively by observing that if n-1 of n weights are
already sorted, it takes at most k+1 more weighings to sort the nth weight.
But, of course, this upper bound is far from perfect, as it equals 8 for 5
weights. So, we can reduce this upper bound to n(k+1) - 2^(k+1) for n
weights or 2^k(k-1) for 2^k weights, but this bound is probably still not
very tight.
-Craig Gentry