Sorting Algorithms - Selection, Bubble, Insertion
Insertion Sort
-go through the list with n elements List[0] List [n-1] and find the right place for each List[k], as k varies between 2 to n.
Selection Sort
-slow -find largest element and swap with the rightmost element, and repeat. -largest item always goes to right end, so the list will be in increasing order.
Bubble Sort
-slow -finds the largest element in each pass through the list and moved it to the end. - does so by swapping out of order pairs
space complexity of bubble sort
O(1)
space complexity of insertion sort
O(1)
space complexity of selection sort
O(1)
time complexity of bubble sort
O(n^2)
time complexity of insertion sort
O(n^2)
time complexity of selection sort
O(n^2)
Stable Sorting Algorithm
keeps equal elements in the same order
Unstable Sorting Algorithm
may or may not keep equal elements in the same order
is Selection sort stable?
no
is bubble sort stable?
yes
is insertion sort stable
yes