0% found this document useful (0 votes)
8 views4 pages

MCQ'S

The document contains a series of questions and answers related to time and space complexity in algorithm analysis, including Big O, Big Omega, and Big Theta notations. Key solutions highlight complexities such as O(n) for a loop printing 'Hello, World!' and O(log n) for binary search. It also discusses implications of function growth rates and relationships between different notations.

Uploaded by

markovluk09025
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views4 pages

MCQ'S

The document contains a series of questions and answers related to time and space complexity in algorithm analysis, including Big O, Big Omega, and Big Theta notations. Key solutions highlight complexities such as O(n) for a loop printing 'Hello, World!' and O(log n) for binary search. It also discusses implications of function growth rates and relationships between different notations.

Uploaded by

markovluk09025
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

Question 1:

What is the time complexity of the following code snippet?

for i in range(n): print("Hello, World!")

a) O(1)
b) O(n)
c) O(log n)
d) O(n^2)

Question 2:

What is the space complexity of the following code snippet?

def find_max(arr): max_value = arr[0] for element in arr: if element > max_value: max_value = element
return max_value

a) O(1)
b) O(n)
c) O(log n)
d) O(n^2)

Question 3:

What is the time complexity of the following code snippet?

for i in range(n): for j in range(n): print(i, j)

a) O(1)
b) O(n)
c) O(n^2)
d) O(log n)

Question 4:

What is the space complexity of the following code snippet?

def fibonacci(n): fib = [0] * (n+1) fib[0], fib[1] = 0, 1 for i in range(2, n+1): fib[i] = fib[i-1] + fib[i-2] return
fib[n]

a) O(1)
b) O(n)
c) O(log n)
d) O(n^2)

Question 5:

What is the time complexity of the binary search algorithm?

a) O(1)
b) O(log n)
c) O(n)
d) O(n^2)

Solution: b) O(log n)

What does Big O notation represent in terms of algorithm analysis?

a) Best-case time complexity


b) Average-case time complexity
c) Worst-case time complexity
d) Exact running time

Question 6:

If a function f(n) is O(g(n)), what does it imply?

a) f(n) grows faster than g(n)


b) f(n) grows at the same rate as g(n)
c) f(n) grows slower than g(n)
d) No relationship between f(n) and g(n)

Question 7:

What does Big Omega (Ω) notation represent in terms of algorithm analysis?

a) Best-case time complexity


b) Average-case time complexity
c) Worst-case time complexity
d) Lower bound on the growth rate of a function

Question 8:

If f(n) = Θ(g(n)), what does it mean?

a) f(n) grows faster than g(n)


b) f(n) grows at the same rate as g(n)
c) f(n) grows slower than g(n)
d) No relationship between f(n) and g(n)
Question 9:

Which of the following statements is true regarding Big O notation?

a) f(n) = O(g(n)) implies g(n) = O(f(n))


b) f(n) = O(g(n)) implies g(n) = Ω(f(n))
c) f(n) = Θ(g(n)) implies g(n) = O(f(n))
d) f(n) = Ω(g(n)) implies g(n) = Θ(f(n))
Question 1: Solution: b) O(n)

Question 2: Solution: O(1)

Question31: Solution: c) O(n^2)

Question 4: O(n)

Question 5: Solution: b) O(log n)

Question 6: Solution: b) O(n)

Question 7: Solutio Worst-case time complexity

Question 8: f(n) grows at the same rate as g(n)

Question 9: f(n) = Θ(g(n)) implies g(n) = O(f(n))

You might also like