Big O Notation Examples
- 41Unfamiliar
- 0Learning
- 0Familiar
- 0Mastered
41 questions
- 1Big O notation is a tool used to analyze algorithms and data structures based on the approximate number of_____in the worst case.
Hint
Think about what we count to estimate how long an algorithm takes.
Answer
operations
- 2Big O notation focuses on what happens when the input size is_____.
Hint
It's about scaling to large inputs, not small ones.
Answer
very large
- 3In time complexity analysis, we consider the_____case scenario to determine Big O notation.
Hint
We want to guarantee an upper bound on runtime.
Answer
worst
- 4The variable_____is commonly used to represent the size of the input.
Hint
It's a standard placeholder for input size.
Answer
n
- 5The first step in determining Big O notation is to find the approximate number of_____for the algorithm.
Hint
What do we count before simplifying?
Answer
operations
- 6In the mathematical definition, f(n)=O(g(n)) means there exist constants c and N such that for all n≥N, $f(n) \leq c \cdot_____$.
Hint
It's the function that bounds f(n) from above.
Answer
g(n)
- 7In the Big O definition, the constants c and N must be at least_____.
Hint
They must be positive, and typically start from 1 or greater.
Answer
1
- 8When simplifying Big O, constants (coefficients) can be_____because they become less important as n grows.
Hint
They don't affect the growth rate.
Answer
dropped
- 9When terms are added together, we keep only the_____term in Big O notation.
Hint
Which term grows fastest as n increases?
Answer
largest
- 10When terms are multiplied together, we_____simply remove the smaller term because both affect the growth rate.
Hint
Multiplication is different from addition.
Answer
cannot
- 11A time complexity of O(1) means that the number of operations is_____regardless of input size.
Hint
It doesn't depend on n.
Answer
constant
- 12O(_____) means that the number of operations grows logarithmically with the input size.
Hint
This complexity is better than linear.
Answer
logn
- 13An algorithm with O(n) time complexity has a_____relationship between input size and operations.
Hint
It's a straight-line increase.
Answer
linear
- 14The time complexity O(nlogn) is typical for efficient_____algorithms.
Hint
Think of common sorting methods like mergesort or heapsort.
Answer
sorting
- 15O(n2) time complexity is often caused by_____loops.
Hint
When one loop runs inside another, each iterating over the input.
Answer
nested
- 16The time complexity O(_____) indicates exponential growth, such as in the naive Fibonacci recursion.
Hint
Each call branches into two more calls.
Answer
2n
- 17The worst time complexity among common functions is O(_____), which is even worse than exponential.
Hint
It's the factorial function.
Answer
n!
- 18For a single loop that iterates n times with constant-time operations inside, the time complexity is O(_____).
Hint
The loop runs n times.
Answer
n
- 19If an algorithm has two separate loops that each iterate over the input of size n, the total time complexity is O(_____).
Hint
The loops are not nested.
Answer
n
- 20For a nested loop where both the outer and inner loops iterate over n elements, the time complexity is O(_____).
Hint
The inner loop runs n times for each of the n outer iterations.
Answer
n2
- 21When an algorithm has two different inputs with sizes n and m, we use notation O(_____) to represent the combined time if the loops are separate.
Hint
We add the contributions from each input.
Answer
n+m
- 22For a nested list with height h and width w, double nested loops over both dimensions give time complexity O(_____).
Hint
Multiply the two dimensions.
Answer
h⋅w
- 23When processing a list of strings, if the longest string has length k, the time to iterate over characters in that string is O(_____).
Hint
The loop runs for each character.
Answer
k
- 24A recursive function that makes two recursive calls and reduces the input by a constant amount (e.g., n−1 and n−2) has time complexity O(_____).
Hint
Think about the Fibonacci sequence.
Answer
2n
- 25A recursive function that makes one recursive call that reduces the input by dividing by 2 (e.g., n/2) has time complexity O(_____).
Hint
The input size reduces by a factor each time.
Answer
logn
- 26A recursive function that makes n recursive calls at each level, where the input decreases by 1, yields time complexity O(_____).
Hint
Think about generating all permutations.
Answer
n!
- 27The built-in function_____
max()on a list of size n has time complexity O().Hint
It needs to examine every element.
Answer
n
- 28Sorting a list of size n using an efficient algorithm (like Python's built-in sort) has time complexity O(_____).
Hint
The best comparison-based sorting is O(n log n).
Answer
nlogn
- 29The operation_____
pop(0)on a Python list of size n has time complexity O() because it shifts all remaining elements.Hint
Removing the first element requires moving all others.
Answer
n
- 30In example 0, checking if a number is even or odd using modulus is an example of_____time complexity.
Hint
It takes the same time regardless of the number.
Answer
constant
- 31In example 1, a loop that sums all numbers in a list has time complexity O(_____).
Hint
The loop runs as many times as there are numbers.
Answer
n
- 32In example 2, nested loops that compare all pairs in a list have time complexity O(_____).
Hint
Both loops iterate over the same list.
Answer
n2
- 33In example 3, two separate loops over two different lists of sizes n and m give time complexity O(_____).
Hint
The loops are not nested.
Answer
n+m
- 34In example 4, processing a nested list with dimensions h and w has time complexity O(_____).
Hint
It depends on both the number of inner lists and their length.
Answer
h⋅w
- 35In example 5 (Fibonacci), the recursive function has time complexity O(_____).
Hint
Each call spawns two more.
Answer
2n
- 36In example 6, calling_____
max()on a list of size n and then searching through a list of size m results in time complexity O().Hint
Both operations are sequential and each is linear in its input.
Answer
n+m
- 37In example 7, a recursive function that divides n by 2 each call has time complexity O(_____).
Hint
The input size halves each step.
Answer
logn
- 38In example 8, processing a list of n strings where each string can be up to length k and sorting each string gives time complexity O(_____).
Hint
Remember to account for both the outer loop and the sorting inside.
Answer
n⋅klogk
- 39In example 9, with dictionaries of sizes n and m, and strings of max length k, the time complexity includes O(nlogn+mlogm plus O(_____) for the while loop processing).
Hint
The while loop repeats for each element and each character removal.
Answer
(n+m)⋅k
- 40In example 11, the triple nested loops give a time complexity of O(_____).
Hint
Count the loops: one outer, two inner.
Answer
n3
- 41In example 12, the recursive function with n recursive calls per level and decreasing input by 1 has time complexity O(_____).
Hint
Think about the number of calls at each level.
Answer
n!

Ask anything
We've read this whole study set, so questions about it get the best answers.