Complete the code to represent the time complexity of a loop that runs n times.
for i in range([1]): print(i)
The loop runs exactly n times, so its time complexity is O(n).
Complete the code to represent the time complexity of a nested loop where both loops run n times.
for i in range(n): for j in range([1]): print(i, j)
The inner loop runs n times for each of the n iterations of the outer loop, so the total is n * n = n².
Fix the error in the time complexity expression for a binary search algorithm.
The time complexity of binary search is O([1])Binary search divides the search space in half each time, so it runs in logarithmic time, O(log n).
Fill the blank to complete the time complexity expression for a function with a loop running n times and a nested loop running log n times.
The time complexity is O(n [1] log n)The total time complexity is the product of n and log n, so O(n * log n).
Fill all three blanks to complete the time complexity expression for a function with a constant time operation, a linear loop, and a quadratic nested loop.
Total time complexity: O([1] + [2] + [3])
The total time complexity adds constant time (1), linear time (n), and quadratic time (n²). The dominant term is n², but the full expression is O(1 + n + n²).