Complete Practice Question Bank
with Worked Solutions (Questions 1-
200)||Latest 2026 |100% Correct
Algorithms & Algorithm Analysis
1. What is the big-O notation for the function f(n) = 5n³ + 2n² log n + 8n + 1?
• A) O(n²)
• B) O(n² log n)
• C) O(n³)
• D) O(n⁴)
• Answer: C) O(n³)
• Solution: The highest-degree term is 5n³, which dominates all other terms as
n approaches infinity. The n² log n term grows slower than n³, so the function
is O(n³) .
2. What is the time complexity of the following algorithm?
text
for i = 1 to n:
for j = 1 to i:
print(i, j)
• A) O(n)
• B) O(n log n)
• C) O(n²)
• D) O(n³)
• Answer: C) O(n²)
• Solution: The outer loop runs n times. The inner loop runs i times,
where i ranges from 1 to n. Total iterations = 1 + 2 + 3 + ... + n =
n(n+1)/2, which is O(n²) .
3. What is the time complexity of a linear search on an unsorted array of size n?
• A) O(1)
, • B) O(log n)
• C) O(n)
• D) O(n²)
• Answer: C) O(n)
• Solution: In the worst case, linear search may need to check all n elements,
resulting in O(n) time complexity .
4. The master theorem solves recurrences of the form T(n) = aT(n/b) + f(n). For
mergesort, a = 2, b = 2, f(n) = n. What is the solution?
• A) Θ(n)
• B) Θ(n log n)
• C) Θ(n²)
• D) Θ(2ⁿ)
• Answer: B) Θ(n log n)
• Solution: Case 2 of the master theorem applies: f(n) = Θ(n^log₂²) = Θ(n),
giving Θ(n log n) .
5. Suppose T(n) = 3T(n/3) + cn. What is T(n) in Θ notation?
• A) Θ(n log n)
• B) Θ(n)
• C) Θ(n²)
• D) Θ(n log² n)
• Answer: A) Θ(n log n)
• Solution: Here, a=3, b=3, log_b a = 1. f(n)=cn, so case 2 applies
(f(n)=Θ(n^1)), resulting in T(n)=Θ(n log n) .
6. Which of the following asymptotic orders is the slowest growing?
• A) O(n!)
• B) O(2ⁿ)
• C) O(n³)
• D) O(n log n)
• Answer: D) O(n log n)
• Solution: Ordered by growth rate (slowest to fastest): O(1) < O(log n) < O(n)
< O(n log n) < O(n²) < O(n³) < O(2ⁿ) < O(n!) .
7. What is the best-case time complexity of bubble sort on an already sorted
list?
• A) O(1)
• B) O(n)
• C) O(n²)
• D) O(n log n)
, • Answer: B) O(n)
• Solution: With an early exit flag, bubble sort can stop after one pass if no
swaps occur, leading to a best-case time complexity of O(n) .
8. The space complexity of a recursive factorial function (without tail-call
optimization) is:
• A) O(1)
• B) O(log n)
• C) O(n)
• D) O(n²)
• Answer: C) O(n)
• Solution: Each recursive call adds a stack frame, leading to O(n) space .
9. What is the time complexity of the while loop in the Sieve of Eratosthenes
algorithm for finding primes up to n?
• A) O(log n)
• B) O(n)
• C) O(n log log n)
• D) O(n²)
• Answer: C) O(n log log n)
• Solution: The Sieve of Eratosthenes has a time complexity of O(n log log n) .
10. Which of the following is not a resource typically analyzed for an algorithm?
• A) Time complexity
• B) Space complexity
• C) Code length
• D) Number of operations
• Answer: C) Code length
• Solution: While important for maintainability, code length is not a standard
measure of algorithmic efficiency .
Counting & Combinatorics
11. What is the cardinality of the power set of a set with 5 elements?
• A) 5
• B) 10
• C) 25
• D) 32
, • Answer: D) 32
• Solution: The cardinality of the power set is 2^n, where n is the number of
elements in the original set. Therefore, 2^5 = 32 .
12. In a standard deck of 52 cards, how many ways are there to choose a hand
of 5 cards?
• A) 52! / 5!
• B) 52! / (5! * 47!)
• C) 52! / 47!
• D) 5^52
• Answer: B) 52! / (5! * 47!)
• Solution: This is a combination problem where order does not matter. The
number of ways to choose 5 cards from 52 is C(52, 5) = 52! / (5! * 47!) .
13. What is the coefficient of the term x³ y² in the expansion of (x + y)^5?
• A) 5
• B) 10
• C) 15
• D) 20
• Answer: B) 10
• Solution: The binomial coefficient for x^(5-2) y^2 is C(5,2) = 5! / (2! * 3!)
= 10 .
14. How many distinct permutations are there of the letters in the word
"MISSISSIPPI"?
• A) 11!
• B) 11! / (4! * 4! * 2!)
• C) 11! / (4! * 3! * 2!)
• D) 11! / (4! * 4!)
• Answer: B) 11! / (4! * 4! * 2!)
• Solution: The word has 11 letters, with M=1, I=4, S=4, P=2. The number of
distinct permutations is 11! / (4! * 4! * 2!) .
15. How many strings of length 5 over the alphabet {A, B, C} are there?
• A) 15
• B) 125
• C) 243
• D) 15,625
• Answer: C) 243
• Solution: There are 3 choices for each of 5 positions: 3⁵ = 243 .