Git Product home page Git Product logo

sorting_algorithms's Introduction

#C++ Sorting Algorithm implementation

A collection of Sorting Algorithm implemented in C++11. See the develop branch for latest version.

Testing

Tested on g++ 4.8.1 on Ubuntu 13.04 Server and Microsoft Visual Studio 2013RC

###Bubble Sort A slow a unuseful sorting algorithm for all but the simplest data sets, or for learning about sorting algorithms.

http://en.wikipedia.org/wiki/Bubble_sort stable
Worst case performance O(n^2)
Best case performance O(n)
Average case performance O(n^2)
Space O(1)

###Cocktail Sort aka Bubble Sort, cocktail shaker sort, ripple sort, shuffle sort, shuttle sort or happy hour sort

A Bubble sort variant which is only marginally more performant. Sorting is performed in both directions on each pass of the array.

http://en.wikipedia.org/wiki/Cocktail_sort stable
Worst case performance O(n^2)
Best case performance O(n)
Average case performance O(n^2)
Space O(1)

###Heap Sort

http://en.wikipedia.org/wiki/Heapsort unstable
Worst case performance O(n log n)
Best case performance Omega(n), O(n log n)
Average case performance O(n log n)
Worst case space complexity O(n) total, O(1) auxiliary

##Insertion Sort An adapted Bubble Sort that alternates between forward and backward passes.

http://en.wikipedia.org/wiki/Insertion_sort stable
Worst case performance O(n2) comparisons, swaps
Best case performance O(n) comparisons, O(1) swaps
Average case performance O(n2) comparisons, swaps
Worst case space complexity O(n) total, O(1)

##Introsort Introsort is a hybrid sorting algorithm that uses Quick Sort to a recursion depth of O(log n) and then switches to a Heap Sort. Heap Sort is implemented using the standard C++ functions make_heap and sort_heap, both of which require Random Access data iterators. For maximum flexibility, this implementation of Introsort does not switch to Heap Sort if the data iterators are not Random Access, and can therefore operator on container with any iterator category.

http://en.wikipedia.org/wiki/Introsort unstable
Worst case performance O(n log n)
Average case performance O(n log n)

###Merge Sort A divide and conquer recursive sorting algorithm which respects the original ordering of elements in the data set with identical keys. Two merge sort algorithms are included; 'merge_sort' an inplace sort that sorts a data set within itself, and a 'merge_sort_copy' which produces a secondary data set conatining the sorted result and leave the original unchanged.

http://en.wikipedia.org/wiki/Mergesort stable
Worst case performance O(n log n)
Best case performance O(n log n) typical, O(n) natural variant
Average case performance O(n log n)
Worst case space complexity O(n) auxiliary

###Min Max Sort An adapted Selection Sort that finds and repositions the Min and Max elements on each pass.

unstable
Worst case performance O(n^2)
Best case performance O(n)
Average case performance O(n^2)
Space O(1)

###Quick Sort A recursive sorting algorithm that works well with a cache, but is unstable; that is elements with identical keys may appear in a different order in the result than they do in the original data set.

http://en.wikipedia.org/wiki/Quicksort unstable
Worst case performance O(n2) (extremely rare)
Best case performance O(n log n)
Average case performance O(n log n)
Worst case space complexity O(n) auxiliary (naive) O(log n) auxiliary (Sedgewick 1978)

###Selection Sort An inplace comparison sorting algorithm that is slow for large data sets, but it is a simple algorithm and has reasonable performance for inplace algorithms.

http://en.wikipedia.org/wiki/Selection_sort stable
Worst case performance O(n^2)
Best case performance O(n^2)
Average case performance O(n^2)
Space O(1)

sorting_algorithms's People

Contributors

cdmh avatar larry-fuy avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.