Skip to content

edwardmartins/sorting-algorithms

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

74 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

A collection of sorting algorithms implemented in C++

A collection of sorting algorithms implemented in C++ to see the advantages and disadvantages of each one of them

Bubble Sort

A slow sorting algorithm for the simplest data sets

Case Performance
Worst case performance O(n^2)
Best case performance O(n)
Average case performance O(n^2)
Auxiliary Space O(1)

bubble-sort-gif-9

Insertion Sort

Insertion sort is a simple sorting algorithm that works the way we sort playing cards. It is efficient for (quite) small data sets.
It is often used when the data set is nearly sorted (it takes minimum time (Order of n)).
It takes maximum time to sort if elements are sorted in reverse order.

Case Performance
Worst case performance O(n^2)
Best case performance O(n)
Average case performance O(n^2)
Auxiliary Space O(1)

1_kra0ofxedgi8hvhjffci4w

Selection Sort

Selection sort is noted for its simplicity, and it has performance advantages over more complicated algorithms in certain situations, particularly where auxiliary memory is limited

Case Performance
Worst case performance O(n^2)
Best case performance O(n^2)
Average case performance O(n^2)
Auxiliary Space O(1)

selectionsort

Merge Sort

Merge Sort is a Divide and Conquer algorithm that continually splits a list in half and then merge the sublists in a sorted way.
A single most important advantage of merge sort over quick sort is its stability: the elements compared equal retain their original order.

Case Performance
Worst case performance O(n log n)
Best case performance O(n log n)
Average case performance O(n log n)
Auxiliary Space O(n)

merge-sort-example-300px

Quick sort

Quick Sort is a recursive sorting algorithm that is more effective than other O(nlogn) algorithms for large datasets that fit in memory, but is unstable. Quick Sort in general does not requiere extra space while Merge Sort requires O(n) extra storage

Case Performance
Worst case performance O(n^2)
Best case performance O(n log n)
Average case performance O(n log n)
Auxiliary Space O(log(n))

quicksort-example