Exam | Data Structures and Algorithms –
Complete Q&A with Rationales – Pass
Guaranteed - A+ Graded
Section 1: Algorithm Analysis & Big O Complexity
Q1: In asymptotic analysis, what does Big O notation primarily describe about an
algorithm?
A. The exact execution time in milliseconds on a specific processor
B. The upper bound of an algorithm's growth rate relative to input size [CORRECT]
C. The lower bound of an algorithm's growth rate
D. The average memory usage across all possible inputs
Correct Answer: B
Rationale: For C949, remember that Big O describes the worst-case growth rate as n
gets large, ignoring constants and lower-order terms; it tells us how the algorithm
scales, not how fast it runs on your particular laptop.
Q2: What is the time complexity of the following algorithm?
,plainCopy
int sum = 0;
for (int i = 0; i < n; i++) {
sum += i;
}
A. O(log n)
B. O(n) [CORRECT]
C. O(n²)
D. O(1)
Correct Answer: B
Rationale: The best answer is B because the loop runs exactly n times, performing a
constant amount of work each iteration; that linear relationship gives us O(n) time
complexity.
Q3: Consider the following code snippet:
plainCopy
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
System.out.println(i * j);
}
}
What is the time complexity of this code?
A. O(n)
B. O(n log n)
C. O(n²) [CORRECT]
,D. O(2^n)
Correct Answer: C
Rationale: Think about the number of operations as input size grows; the outer loop
runs n times and the inner loop runs n times for each outer iteration, giving n × n total
iterations, which is quadratic growth.
Q4: Which time complexity best describes the worst-case scenario for binary search on
a sorted array of size n?
A. O(n)
B. O(log n) [CORRECT]
C. O(n log n)
D. O(1)
Correct Answer: B
Rationale: The best answer is B because binary search halves the search space every
iteration; even in the worst case, you only need log₂(n) comparisons to narrow down to a
single element.
Q5: Quicksort has an average-case time complexity of O(n log n). What is its worst-case
time complexity, and under what condition does it typically occur?
A. O(n²), when the pivot selection consistently splits the array into highly unbalanced
partitions [CORRECT]
B. O(n log n), regardless of how pivots are chosen
, C. O(n), when the array is already sorted
D. O(log n), when using the first element as the pivot
Correct Answer: A
Rationale: The best answer is A because if you keep picking the smallest or largest
element as the pivot—like always choosing the first element on sorted data—you get
one empty partition and one partition of size n-1, which degrades to quadratic time.
Q6: Which of the following best describes the space complexity of a standard recursive
implementation of merge sort?
A. O(1)
B. O(log n) for the recursion stack only
C. O(n) due to the auxiliary array needed for merging [CORRECT]
D. O(n²)
Correct Answer: C
Rationale: The best answer is C because merge sort needs a temporary array to hold the
merged result; that auxiliary array is proportional to n, giving it O(n) space complexity
even though the recursion stack is only O(log n).
Q7: In asymptotic notation, Big Omega (Ω) is used to represent which bound on an
algorithm's growth rate?
A. Upper bound
B. Lower bound [CORRECT]