Question 31
MediumWhat is the time complexity of this code?
i = 1
while i * i <= n:
i += 1
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?
i = 1
while i * i <= n:
i += 1
O(log n)
O(n)
O(√n)
O(n²)
Sign up free to see the answer and a step-by-step explanation.
Which recurrence describes merge sort, and what does it solve to?
T(n) = T(n − 1) + O(1), which is O(n)
T(n) = T(n/2) + O(n), which is O(n²)
T(n) = 2T(n/2) + O(n), which is O(n log n)
T(n) = 2T(n/2) + O(1), which is O(log n)
Sign up free to see the answer and a step-by-step explanation.
What is the space complexity of a recursive function that recurses n levels deep using O(1) memory per call?
O(1)
O(n)
O(n²)
O(log n)
Sign up free to see the answer and a step-by-step explanation.
What is the amortised time complexity of appending to a dynamic array (like a Python list) that doubles its capacity when full?
O(log n)
O(n²)
O(n)
O(1)
Sign up free to see the answer and a step-by-step explanation.
What is the time complexity of this code?
i = n
while i > 0:
for j in range(i):
work()
i //= 2
O(n²)
O(n)
Sign up free to see the answer and a step-by-step explanation.
What is the time complexity of this code?
for i in range(n):
j = 1
while j < n:
work()
j *= 3
O(log n)
O(n²)
Sign up free to see the answer and a step-by-step explanation.
What is the time complexity of this code?
for i in range(n):
for j in range(i, n):
for k in range(j, n):
work()
O(n)
O(n²)
Sign up free to see the answer and a step-by-step explanation.
What is the time complexity of this code?
def f(n):
if n <= 1:
return
f(n // 2)
f(n // 2)
for i in range(n):
work()
O(n log n)
O(n)
Sign up free to see the answer and a step-by-step explanation.
What is the time complexity of this code?
def g(n):
if n <= 1:
return 1
return g(n - 1) + g(n - 1)
O(n log n)
O(n²)
Sign up free to see the answer and a step-by-step explanation.
What is the time complexity of this code?
i = 2
while i < n:
i = i * i
O(log n)
O(log log n)
O(n)
O(√n)
Sign up free to see the answer and a step-by-step explanation.
O(log n)
O(n log n)
O(n)
O(n log n)
O(n² log n)
O(n³)
O(log n)
O(n²)
O(n)
O(2ⁿ)