Finding Faster Algorithms Flashcards
exponentiation vs. faster exponentiation
O(n) vs. O(k)
What is memoization
Intermediate values returned by the function can be memoized, or saved in a cache, for subsequent access
They don’t have to be recomputed!
fib vs. fastFib
somewhere between O(1^n) and O(2^n) vs. O(n)
selection sort vs. quick sort
O(n^2) vs. best case O(nlog2(n)) worst case O(n^2)
When will quick sort degrade to O(n^2)?
When the value at the midpoint is near the largest or smallest value on each call (there will be approximately n subdivisions)
Other methods of selecting the pivot element
Pick a random element
Pick the median of the first three elements
Pick the median of the first middle and last elements
Pick the median element - not!!! This is an O(n) algorithm