sorting Flashcards
selection sort runtime
O(N^2)
number of comparisons in selection sort
(N-1)*N/2
How many times longer will sorting a list of 20 elements take compared to sorting a list of 10 elements?
20^2 / 10^2 = 4
selection sort’s runtime grows _______with the input size
quadratically
insertion sort runtine
O(N^2)
in insertion sort the outer loops executes ______ times
N-1
in insertion sort the inner loop executes on average _______ times
N/2
First iteration (i = 1) requires at most 1 comparison, second iteration requires at most 2 comparison, the third 3 comparison, and so on.
x
For sorted or nearly sorted inputs, insertion sort’s runtime is …
O(N)
The worst-case performance for insertion sort is when the list elements are in…
descending order
midpoint in quicksort
i + (k -i) / 2
quicksort time complexity
O(N*logN)
If the number of elements in the numbers array is even, the midpoint value is rounded …
down
in quicksort there are ______ partitioning levels
log2 N
in quicksort there are ______ comparisons
N * log2 N