There's an array of values from 1 to n. It isn't sorted. We have to sort it, but there are only to ways to move: third element to beginning or last element to beginning. How to do that ?
Name:
Anonymous2010-10-24 11:16
>>14 2 1 3 4: 4 2 1 3 (last-->1) 3 4 2 1 (3-->1) 2 4 3 1 (3-->1) 1 2 4 3 (last-->1) 4 1 2 3 (3-->1) 3 4 1 2 (last-->1) 2 3 4 1 (last-->1) 1 2 3 4 (last-->1)[/m]
The real question is if you can build an intuitive algorithm out of these two rules. I doubt the problem can be made to compute in polynomial time.