Sorting Without Comparison
Source: College homework problem.
You are given two numbers (a, b) and you wish to assign one each to (A, B)
such that A<=B. That is, you want A to equal the minimum of a and b, and
B to equal the maximum of a and b. How can you write A=f(a,b), and B=g(a,b,A)
to correctly assign the values? Try to make functions f and g as simple as
Can you extend the above result for three original numbers (a, b, and c)
to be assigned to A<=B<=C?
Can you extend it to four numbers simply?
- Is there a general approach for more numbers, or is a repetitive
Mail to Ken