Chrome Browser Usage Artificially Boosted in Back Page News


Photo * * * * * 1 votes

Sort Algorithm Complete!

After a nightmarish ordeal of attempting to get the range swap to work, I finally found the two problems causing the code not to work. It's always something simple. Posted Image I finished the optimized version of my algorithm, and I'm quite happy with the result.

These are some attributes of my sorting algorithm:
  • It is a stable sort
  • Low memory requirement (only a few extra KiB is required)
  • It's a divide and conquer algorithm, which makes it easy to parallelize
  • Good performance (not as fast as quick sort, but only a little bit slower than merge sort, and faster than shell sort)
  • Faster on sorted or partially sorted data
  • Similar to Timsort, except for the range swap
  • The range swap is pretty fast at reversing elements in descending order
  • Minimal risk of stack overflow using tail calls
For greater detail on the sorting algorithm, see my previous blog posts:
Designing a sorting algorithm
Sort Algorithm pt. 2

You can download the source code here. This contains a simple text file as well as an HTML file with syntax highlighting. It contains the source for my sort as well as all of the other algorithms I implemented for scrutinies sake.
Download xinokSort.zip | Mirror

I have also started an open source project to implement this sorting algorithm in many programming languages.
Xinok Sort on SourceForge



Now for some benchmarks! The benchmarks of shell sort and quick sort are faster than in previous posts because I further optimized them. The characters on the right are MD5 hashes, to verify the array was sorted correctly.

Shuffled:
Posted Image

Shuffled 4x Larger Array: (To show how well my algorithm scales) (there wasn't enough memory left for radix sort)
Posted Image

Sorted Array:
Posted Image

Partially Sorted Array: (2048 elements were swapped and out of place)
Posted Image

Reversed Array: (elements are in descending order)
Posted Image



Nice! I'll keep this as a reference in case I need a custom sorting algorithm, this looks pretty neat.

Recent Entries

Recent Comments