2.2 Runtime Analysis Flashcards
What is running time complexity of Insertion sort (best and worst cases)?
Best: n - 1
Worst: (n^2 - n) / 2
How do you calculate the runtime complexity of mergeSort
n * height of the tree
How do you calculate the height of the tree in MergeSort
Log(2)N
What is the runtime complexity of MergeSort
N * Log(2)N
Draw the symbols for a quadratic function for:
grows at most
grows at least
grows exactly
grows slower than
grows faster than
Order these by asymptotic growth:
n^3
1
sqrt(n)
nlogn
n
n^2
2^n
logn
1
logn
sqrt(n)
n
nlogn
n^2
n^3
2^n
Worst case, average and best case runtime complexity for insertion sort
Worst: O(n^2)
Average: O(n^2)
Best: O(n)
Worst case, average and best case runtime complexity for MergeSort sort
O(nlogn)
Worst case, average and best case runtime complexity for HeapSort sort
O(nlogn)
Is InsertionSort stable? If there are 2 1’s in the array will the first 1 always stay before the second 1?
Yes
Can insertion sort be done in situ (using only the array you were given and no extra space)
Yes