in reply to Re^3: Fast way to check if a sort was doen
in thread Fast way to check if a sort was doen
Walk the original array testing if each element is in the position it is supposed to be (same as your sort block). If you get to the end, your array is already sorted and there is no need to sort it. If you find an element out of order than you know the array needs to be sorted (which will change the order).
The trick is that you can't actually both know that the array needs to be sorted and sort it in better than O(N). At least I couldn't think of a way in the 2 minutes I spent thinking about it.
Cheers - L~R
|
---|