Reputation: 430
This might be frivolous question, so please have understanding for my poor soul.
After reading this article about Intelligent Design sort (http://www.dangermouse.net/esoteric/intelligentdesignsort.html) which is in no way made to be serious in any way, I started wondering whether this could be possible.
An excerpt from article says:
The probability of the original input list being in the exact order it's in is 1/(n!). There is such a small likelihood of this that it's clearly absurd to say that this happened by chance, so it must have been consciously put in that order by an intelligent Sorter.
Let's for a second forget about intelligent Sorter, and think about possibility that random occurrences of members in array are in some way sorted. Our algorithm should determine the pattern without changing array's structure.
Is there any way to do this? Speed is not a requirement.
Upvotes: 2
Views: 1461
Reputation: 488
The implementation is very easy actually. The entire point of the article is that you don't actually sort anything. In other words, a correct implementation is a simple NOP
. As my preferred language is Java, I'll show a simple in-place implementation in Java as a lambda function:
list->{}
Upvotes: 2
Reputation: 4809
Funny article, I had a good laugh.
If the only thing you're interested in is that whether your List
is sorted, then you could simply keep an internal sorted
flag (defaulted to true
for an empty list) and override your add()
method to check if the element you're adding fits the ordering of the List
- that is, compare it to the adjacent elements and setting the sorted
flag appropriately.
Upvotes: 0