Tuesday, January 12, 2010

Reversable sorting algorithm CONTEST

Most of you guys out there know a few things about sorting, there are lots of sorting algorithms and from what I know Quick Sort is the fastest.
More information about sort algorithms can be found on Wikipedia(click for link).

As you know a sort algorithm can sort an array of bytes/chars/integers/etc. in ascending or descending order, but what IF I wish to sort a array of bytes/chars/integers/etc.(of variable length) in any order(ascending or descending) and store some information that helps me restore it to initial state?

Contest rules:
- Develop a sort algorithm which sorts a array of bytes/chars/integers/etc.(in ascending and/or descending order) which stores information that helps you restore the array in initial state.
- The sort information must NOT use more than half the size of the array(i.e. we have a array of bytes of 4096 elements, the sort information must not use more than 2048 bytes)
- If you use code written by other people you must enter a comment before the code in the source code(i.e. this code is created by AUTHOR NAME|link to website on next line the code appears).
- The algorithm must work on any number of elements in a array

The application/unit/source code must be sent to me at this e-mail address: duminicadorin{AT}gmail{DOT}com(you can send me e-mail if you do not understand any of the above rules -- comments are also welcomed).

The winning code will be the fastest algorithm or the algorithm which stores information about the sort in less space.

Prizes:
1st place: a 4GB memory stick and a customized T-Shirt
2nd place: a 2GB memory stick
I will request your address in order to send you the prize IF AND ONLY IF YOU WIN 1st or 2nd place.

8 comments:

By the way, it rReminds me a cool story. I asked once on a forum on information theory whether a sorted list of words contains more or less information than the same list, but unsorted. I was pretty convinced a sorted dictionary or phone book contains more information since you can retrieve data much easily than if it wasn't sorted. But I got this answer : "an contains information list more unsorted" :-)

Well I had more than enough time to think about it, but I didn't code anything. Because in fact there is no solution.

Sorting an array of n records with a good algorithm looses n.log(n) bits of information, which are the results of the n.log(n) comparisons. You could imagine storing those and write an "unsort" function, but it's even simpler to realize that the original index of each element also requires log(n) bits, so a simple table of the initial index of each elements also takes n.log(n) bits !

So in short there is no way to fulfil the requirement that "The sort information must NOT use more than half the size of the array(i.e. we have a array of bytes of 4096 elements, the sort information must not use more than 2048 bytes)" : for 4096 elements, you need at least 4096*log(4096)=4096*12=6K bits.

At one point I thought one could use the Burrows-Wheeler transform (http://en.wikipedia.org/wiki/Burrows%E2%80%93Wheeler_transform), which makes data "more compressible", but it doesn't perform a real sort.

However, I believe there might be specific solutions based on compression for data with high redundancy.

Also, I'd be very pleased to be wrong and would really love to see a solution to this problem, because it would be equivalent to a sort algorithm with O(n) complexity.

@drgoulu Oh man! if you could have just e-mailed the this in time you would have been declared the winner, unfortunately no one e-mailed, I'm am not sure about your calculations, but the point is that there is no solution from what I am awear.I already told that the solution is "out of the box" by that I mean that anyone who participated in the contest should have thought first if it's possible first and then start to waste time, anyways this is a good exercise for beginners, "think first, act after".I really like the way you think, I hope you participate on Delphi Torrent client contest because it's doable :) and it should not take too much time, have fun and I'm sorry you didn't e-mailed me, because you would have won first prize!