views:

123

answers:

2

I have this linked list containing hashed values of a set images. I am plan to run a simplistic but a very quick sort for the same and so far I am stuck with just two of them, merge sort and quick sort.

My quick sort implementation seems to have gone haywire and is taking a painstakingly long 15 seconds (approx.) to sort out over 10 images. Merge sort seems to be working fine but it just doesnt seem that fast (approx. 3 seconds).

Any other suggestions would be fine too.

P.S.: I am building an image viewer for windows mobile and my main criteria for the application is speed, jut that I need a sorting algorithm for sorting the images via their ranging contrast levels. (Its just an experiment).

Any other inputs would be really helpful too.

+2  A: 

How about using a sorted list that places the image in the correct position at insert time? You'll still have the cost of finding the insertion point but it might be more user-friendly e.g. if the user is manually choosing from a list of pictures then a slightly longer insert time could be OK.

monorailkitty
hmmm......insertion sort seems like a nice alternative, I haven't thought of the manual approach as of now but thats for later. Thanks
Techeretic
+1  A: 

Note that quick sort requires access to arbitrary elements in the array in constant time O(1) to work fast. Linked list takes O(n)...

Viliam
Doesn't explain why the algorithms are so slow with such small n, but still a very good point.
Mark Ransom
I agree, but then my linked list is double ended, I usually start from the new image that was added or the middle element in the list (sorted previously by filenames (i know it doesn't matter))
Techeretic
just realised that even a double ended linked list will take O(n), thanks for that
Techeretic