Space and Time Complexity Flashcards
(47 cards)
What is time complexity?
A measure of the amount of time an algorithm takes as a function of input size.
What is space complexity?
A measure of the amount of memory an algorithm uses as a function of input size.
What is Big O notation?
A mathematical notation used to describe the upper bound of an algorithm’s runtime or space usage.
What does O(1) mean?
Constant time or space — independent of input size.
What does O(n) mean?
Linear time or space — grows directly with input size.
What does O(log n) mean?
Logarithmic time or space — grows slowly even for large inputs.
What does O(n log n) mean?
Linearithmic complexity — typical of efficient sorting algorithms.
What does O(n^2) mean?
Quadratic time or space — often results from nested loops.
What does O(2^n) mean?
Exponential complexity — grows very quickly with input size.
What does O(n!) mean?
Factorial time — extremely slow, used in brute-force permutations.
What is worst-case complexity?
The maximum amount of time or space an algorithm can take.
What is best-case complexity?
The minimum amount of time or space an algorithm can take.
What is average-case complexity?
The expected amount of time or space across typical inputs.
What is amortized complexity?
The average time per operation over a sequence of operations.
What is auxiliary space?
Extra space or temporary space used by an algorithm.
What is in-place algorithm?
An algorithm that uses only a constant amount of extra space.
What is the time complexity of binary search?
O(log n)
What is the time complexity of linear search?
O(n)
What is the space complexity of recursive algorithms?
O(depth of recursion) due to call stack.
What is the time complexity of quicksort on average?
O(n log n)
What is the worst-case time complexity of quicksort?
O(n^2)
What is the time complexity of merge sort?
O(n log n) in all cases.
What is the space complexity of merge sort?
O(n) due to auxiliary arrays.
What is the time complexity of heap sort?
O(n log n)