Skip to content

Fast and stable merge sort algorithm that uses O(1) memory

License

Notifications You must be signed in to change notification settings

townie/WikiSort

 
 

Repository files navigation

WikiSort

WikiSort is a stable bottom-up in-place merge sort based on the work described in "Ratio based stable in-place merging", by Pok-Son Kim and Arne Kutzner [PDF]. Kim's and Kutzner's algorithm is a stable merge algorithm with great performance characteristics and proven correctness, but no attempt at adapting their work to a stable merge sort apparently existed. This is one such attempt!

What separates this from those other in-place merge papers?
Dr. Kutzner's and Dr. Kim's paper addresses this, but many of the papers define algorithms that are unstable, impractical (as in too slow to be of general use), or theoretical. Their paper is one of the few to provide a full implementation for a fast and stable in-place merge, and the published performance results were promising.

Head-to-head
  • 80-90% of the speed of libc++'s stable_sort() for highly random input with fewer than ~10 million elements.
  • Starts to exceed stable_sort()'s performance for larger arrays (not yet sure why – needs more research).
  • Up to 10x faster when the data is already partially sorted or otherwise has a less-than-random distribution.
  • 3-15x faster than inplace_stable_sort(), which is libc++'s equivalent O(1) sort function.

If you want to know how it works, check out the documentation:
  • Chapter 1: Tools
  • Chapter 2: Merging
  • Chapter 3: In-Place
  • Chapter 4: Faster!

WikiSort is fast, stable, uses O(1) memory, and public domain! It will also change as superior techniques become known – if you see something in the algorithm that could be improved, please flag the issue!

C, C++, and Java versions are currently available. Please note that while it is already highly practical, it is not yet a 100% implementation of their work.

Quick extra note: If you're wondering what to call this type of sort, the authors suggested "block merge-sort", as it would fit the existing pattern of "heap sort" and "weak heap sort". I guess KimSort is a no-go.

About

Fast and stable merge sort algorithm that uses O(1) memory

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published