Sorting and General Flashcards
What is the best-case time complexity of insertion sort?
O(n)
What is the time complexity of insertion sort?
O(n^2)
What term describes an algorithm which improves in performance for certain inputs?
Adaptive
What input hits the worst case of insertion sort?
Reverse order
What input hits the best case of insertion sort?
Already sorted
What is the space complexity of insertion sort?
O(1)
How can we improve on trickle-down insertion sort?
Instead of swapping all the way down (which uses three assignments per swap), first determine the location to insert at, store a[i] in a temp variable, and trickle up from a[j] (one assignment per iteration)
Give the formal definition of what it means for a function f(n) to be O(g(n))
There are constants k,N > 0 such that for all n > N . f(n)
Give the informal definition of what it means for a function f(n) to be O(g(n))
f(n) grows at most like g(n)
Give the formal definition of what it means for a function f(n) to be θ(g(n))
There are constants j,k,N > 0 such that for all n > N . 0
Informally, what does it mean for a function f(n) to be θ(g(n))
f(n) grows exactly like g(n)
Informally, what does it mean for a function f(n) to be Ω(g(n))?
f(n) grows at least like Ω(g(n))
What do small-letter complexity classes indicate?
A stricter version of the same big-letter classes. E.g. f(n) is o(g(n)) means f(n) grows “strictly more slowly” than g(n)
When is amortized analysis useful?
When analysing data structure operations which are performed in sequence
What technique can be used to minimise the cost of exchanges when sorting arrays of large chunks of data?
Sorting by proxy: create an array of indices, do comparisons on the data and exchange the indices