Friday, December 04, 2009

SimpleSort

This is an algorithm to compete with the current slowest sorting algorithms.

1. We're given our list to sort, L
2. Create a list of length 0, M
3. Randomly, either append a random* value to the end of M, or remove the last value. If M has length 0 then we do not remove the last non-existent value.
4. Check if all elements of M are in L.**
5. If yes, check if all elements of L are in M.
6. If yes, check if M is in order.***
7. If no, repeat from Step 3. If yes, we've sorted it.

* this could be problematic.
if it's an int of size 32 for example, we can just add a number from -2^31 to 2^31-1.
if it's a float, we could do something similar for the 80-bit or 64-bit floating point value.
if it's a bignum, we can apply step 3 to the number itself as a string of digits.
if it's a string, we could also apply step 3 here.
if it's some arbitrary object, we can randomize every primitive type it's composed of in the above manners

** something like:
for x in M:
if not x in L:
break
else:
it's in there.
and vice versa for Line 5.

*** something like:
M += [+inf]
for i in 0...len(M):
if M[i] > M[i+1]:
break
else:
it's sorted

1 comment:

Anonymous said...

Ok so I'd usually download the version from iTunes and plug in my iPhone and it'd work. But it won't this time, is there any way I can possible get the new version but without using iTunes ? Like directly from a website or something ? Thanks a looot :)
[url=http://unlockiphone22.com]unlock iphone[/url] [url=http://thinkandcreate.net/showthread.php?p=44149#post44149]unlock iphone[/url]