Explain how Selection Sort works
Explain how Insertion Sort works
Explain how Merge Sort works
Explain how Quick Sort works
Pivot conditions:
ItemOnLeft - Starting from the left of the array, the first item that is larger than the pivot
ItemOnRight - Starting from right of the array, the first item that is smaller than the pivot
Explain how Heap Sort works
Explain how Radix Sort works
R= Radix (base system) d = # of digits
What is the best case complexity for Selection sort?
Theta(n^2)
What is the worst case complexity for Selection sort?
Theta(n^2)
What is the average case complexity for Selection sort?
Theta(n^2)
What is the best case complexity for Insertion sort?
Theta(n)
What is the worst case complexity for Insertion sort?
Theta(n^2)
What is the average case complexity for Insertion sort?
Theta(n^2)
What is the best case complexity for Merge sort?
Theta(nlog(n))
What is the worst case complexity for Merge sort?
Theta(nlog(n))
What is the average case complexity for Merge sort?
Theta(nlog(n))
Why are the complexities for Selection Sort the same?
Regardless of how much the array is sorted at the beginning, we will always have to iterate through n, n-1, n-2, …. 2, 1 indicies. This is n^2 time
Why are the complexities for Insertion sort different?
If the array is already sorted, the number of swaps needed is 0, meaning we only have to do n comparisons and no swaps.
Why are the complexities for Merge Sort the same?
At every recursive level we have Theta(n) operations. The number of levels is log(n). Regardless of how sorted the array is at the beginning, this is the case
What is the best case complexity for Quick sort?
Theta(nlog(n))
What is the worst case complexity for Quick sort?
Theta(n^2)
What is the average case complexity for Quick sort?
Theta(nlog(n))
Why is there a difference between the worst and best case complexity for Quick Sort?
It all depends on how you pick your partition. The best case will have a perfectly balanced partition while the worst case will have every partition include only one element.
What is the average complexity for LSD Radix Sort?
Theta(m(n+R))
Where m = # of digits
R = Radix (base)
Can Radix sort to better than comparison based sorting?
Yes, Radix can get to o(nlog(n))