comp 2 num 2 Flashcards
What is an algorithm?
Step by step instructions to solve a problem.
What is O(1)?
constant time complexity, Time requirements do not change as the size of the input increases.
What is O(n)?
linear time complexity, Time requirements increase in direct proportion to the size of the input.
What is O(n^2)?
quadratic time complexity, Time requirements increase in proportion to the size of the input squared.
What is O(n^k)?
polynomial time complexity
What is O(k^n)?
exponential time complexity, A small increase in the size of the input results in a disproportionate exponentially large increase in the time requirements.
What is O(logn)?
logarithmic time complexity, As the size of the input increases, the time requirements increase at a decreasing rate.
What is the best to worst order for these?
1
logn
n
nlogn
n^2
n^k
k^n
What is always the best case time for a search algorithm?
o(1)
What is the worst case time complexity for each search/sort alg?
linear search n
binary search logn
bubble sort n^2
insertion sort n^2
merge sort nlogn
quick sort nlogn
Why is a merge sort nlogn?
Splitting array recursively until all arrays are of length 1 is logn.
Combining these n number of sublists results in multiplying by n to result in nlogn.
What is the purpose of big o?
Evaluating the complexity of an algorithm in relation to space and time requirements and how they scale as the input size increases.