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++ to see the advantages and disadvantages of each one of them

A slow sorting algorithm for the simplest data sets

CasePerformance
Worst case performanceO(n^2)
Best case performanceO(n)
Average case performanceO(n^2)
Auxiliary SpaceO(1)

bubble-sort-gif-9

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.

CasePerformance
Worst case performanceO(n^2)
Best case performanceO(n)
Average case performanceO(n^2)
Auxiliary SpaceO(1)

1_kra0ofxedgi8hvhjffci4w

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

CasePerformance
Worst case performanceO(n^2)
Best case performanceO(n^2)
Average case performanceO(n^2)
Auxiliary SpaceO(1)

selectionsort

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.

CasePerformance
Worst case performanceO(n log n)
Best case performanceO(n log n)
Average case performanceO(n log n)
Auxiliary SpaceO(n)

merge-sort-example-300px

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

CasePerformance
Worst case performanceO(n^2)
Best case performanceO(n log n)
Average case performanceO(n log n)
Auxiliary SpaceO(log(n))

quicksort-example