Question 61
HardWhat is the time complexity of this code?
for i in range(, n + ):
j = i
j <= n:
work()
j += i
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?
for i in range(, n + ):
j = i
j <= n:
work()
j += i
O(n log n)
O(n²)
O(n)
O(n √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
for i in range(n):
work()
f(n // 3)
f(n // 3)
f(n // 3)
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 f(n):
if n <= 1:
return 1
return f(n - 1) + f(n - 2)
O(2ⁿ) exactly, and no tighter
O(n log n)
Sign up free to see the answer and a step-by-step explanation.
What is the time complexity of this code?
i, s = 1, 0
while s < n:
s += i
i += 1
O(n²)
O(log n)
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):
for j in range(i * i):
work()
O(n³)
O(n log 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)
for i in range(n * 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?
k = 1
while k < n:
for i in range(k):
work()
k *= 2
O(n)
O(log n)
Sign up free to see the answer and a step-by-step explanation.
What does T(n) = 2T(n/4) + √n solve to?
Θ(√n)
Θ(√n log n)
Θ(log n)
Θ(n)
Sign up free to see the answer and a step-by-step explanation.
What does T(n) = 7T(n/2) + n² solve to (Strassen's algorithm)?
Θ(n³)
Θ(n^log₂7) ≈ Θ(n^2.81)
Θ(n² log n)
Θ(n²)
Sign up free to see the answer and a step-by-step explanation.
What does T(n) = T(n − 1) + log n solve to?
Θ(n log n)
Θ(log n)
Θ(n)
Θ(log² n)
Sign up free to see the answer and a step-by-step explanation.
O(n)
O(n^log₃2)
O(n²)
O(φⁿ), about O(1.618ⁿ)
O(n⁴)
O(n²)
O(n²)
O(n² log n)
O(n²)
O(n log n)