Question 41
MediumWhat is the time complexity of this code?
total, k = 0, 1
while total < n:
total += k
k +=
Popular companies
Prepare company by company
Hiring pattern, syllabus, past questions and mocks for each company.
All companiesPractice by subject
Data Structures and Algorithms
What is the time complexity of this code?
total, k = 0, 1
while total < n:
total += k
k +=
O(n²)
O(n)
O(log n)
O(√n)
Sign up free to see the answer and a step-by-step explanation.
T(n) = 3T(n/2) + n. By the Master Theorem, what is T(n)?
Θ(n)
Θ(n log n)
Θ(n^log₂3) ≈ Θ(n^1.585)
Θ(n²)
Sign up free to see the answer and a step-by-step explanation.
T(n) = 4T(n/2) + n². By the Master Theorem, what is T(n)?
Θ(n² log n)
Θ(n³)
Θ(n²)
Θ(n log n)
Sign up free to see the answer and a step-by-step explanation.
Naive divide-and-conquer matrix multiplication splits n × n matrices into quarters and makes 8 recursive multiplications plus O(n²) additions. What is its running time?
Θ(n⁴)
Θ(n³)
Θ(n² log n)
Θ(n²)
Sign up free to see the answer and a step-by-step explanation.
Which ordering of growth rates is correct, from slowest to fastest?
log n, n, √n, n log n, 2ⁿ, n²
log n, √n, n, n log n, n², 2ⁿ
√n, log n, n, n², n log n, 2ⁿ
n, log n, √n, n², n log n, 2ⁿ
Sign up free to see the answer and a step-by-step explanation.
An algorithm takes 3 seconds for n = 1,000 and 24 seconds for n = 2,000. What is its likely complexity?
O(n³)
O(2ⁿ)
O(n log n)
O(n²)
Sign up free to see the answer and a step-by-step explanation.
A dynamic array doubles its capacity when full. What is the total copying cost of n appends?
O(log n)
O(n log n)
O(n²)
O(n)
Sign up free to see the answer and a step-by-step explanation.
If a dynamic array grows by a fixed 10 slots instead of doubling, what is the total cost of n appends?
O(n)
O(n log n)
O(n²)
O(1)
Sign up free to see the answer and a step-by-step explanation.
What is the space complexity of merge sort on an array, including the recursion stack?
O(n log n)
O(1)
O(n)
O(log n)
Sign up free to see the answer and a step-by-step explanation.
What is the auxiliary space of iterative binary search?
O(1)
O(log n)
O(n)
O(n log n)
Sign up free to see the answer and a step-by-step explanation.