Source: class WhatsApp group (Chats/WhatsApp-Cheat-code/chat.md), "DAA QUIZ" set posted after the Assignment-2 paper (13 Oct 2026).
Status: ✅ all 25 re-derived — 25/25 correct.
Quick answer key
| Q | Ans | Q | Ans | Q | Ans | Q | Ans | Q | Ans |
|---|---|---|---|---|---|---|---|---|---|
| 1 | False | 6 | False | 11 | False | 16 | b | 21 | b |
| 2 | c | 7 | a | 12 | c | 17 | False | 22 | c |
| 3 | d | 8 | c | 13 | b | 18 | a | 23 | c |
| 4 | b | 9 | c | 14 | d | 19 | False | 24 | b |
| 5 | a | 10 | True | 15 | c | 20 | d | 25 | a |
Q1. Proving termination is sufficient to prove correctness.
✅ False — termination only says the algorithm stops. Correctness needs partial correctness (the output satisfies the spec if it stops) + termination. Related: that pair is "total correctness".
Q2. Binary search on a sorted array of 1,023 elements — max comparisons (usual midpoint search)?
a. 31 b. 8 c. 10 d. 12
✅ c — 10. 2¹⁰ = 1024 > 1023, so ten halvings suffice. Related: 31 would be the answer for linear search of the same array; 8 = log₂256.
Q3. Insertion sort on an array where exactly k elements are out of place: which description fits?
a. Depends only on the maximum element b. Always Θ(n log n) c. Always Θ(n) d. Θ(n + I), where I is the number of inversions
✅ d — Θ(n + I). Each swap removes exactly one inversion; the scan is n. Related: I ranges from 0 (sorted → Θ(n)) to n(n−1)/2 (reverse sorted → Θ(n²)) — which is why "always Θ(n)" and "always Θ(n log n)" are both impossible.
Q4. Which statement correctly describes the maintenance step of a loop-invariant proof?
a. Proves the invariant holds before the loop b. Proves that if it holds before an iteration, it holds after that iteration c. Proves termination d. Establishes the lower bound
✅ b. Initialisation (before the loop) → Maintenance (each iteration) → Termination (gives the post-condition). Related: the three steps are exactly the induction base, step and conclusion.
Q5. Closest-pair of n points — worst case with efficient initial sort and strip processing?
a. Θ(n log n) b. Θ(n² log n) c. Θ(n²) d. Θ(n)
✅ a — Θ(n log n). Sort by x once (Θ(n log n)); the strip is scanned in y-order with at most 7 neighbours compared per point (the classic packing argument), so the recursion is T(n)=2T(n/2)+Θ(n). Related: the naive all-pairs algorithm is Θ(n²) — that is option (c).
Q6. Binary search can be applied to a sorted linked list with the same Θ(log n) run time.
✅ False — indexing into the middle of a linked list costs O(n). Binary search needs O(1) random access. Related: you can build a balanced search tree or skip list to get O(log n) on linked structures.
Q7. Linear search over n distinct elements, key guaranteed present and uniformly located — expected comparisons?
a. (n+1)/2 b. n log n c. n−1 d. log n
✅ a — (n+1)/2. Average of 1..n. Related: the worst case is n; the expected value for an unsuccessful search is n.
Q8. Recursive n! via F(n) = n·F(n−1) — which additional condition is essential for a correctness proof?
a. O(n log n) run time b. Recursion depth exactly log n c. A correct base case d. Must use a loop
✅ c — a correct base case. Without F(1) = 1 the recursion never bottoms out and the theorem proves nothing.
Q9. Insertion sort shifts only while (A[j] > key), not (≥). Consequence with duplicates?
a. Becomes quadratic in the best case b. Becomes unstable c. Remains stable d. No longer sorts correctly
✅ c — remains stable. Stopping at an equal element leaves the earlier equal element in front. Related: using ≥ lets the new element jump ahead of equals, which breaks stability — that is the trap.
Q10. Merge sort and insertion sort are both stable in their standard versions.
✅ True.
Q11. Insertion sort performs Θ(n³) on every input of size n.
✅ False — Θ(n²) worst case, Θ(n) best case.
Q12. A = [5,2,4,6,1,3] after the 3rd iteration of the outer loop of standard insertion sort?
a. [2,4,5,6,1,3] b. [1,2,4,5,6,3] c. [2,4,5,6,1,3] d. [2,5,4,6,1,3]
✅ c. Iteration 1 → [2,5,4,6,1,3]; iteration 2 → [2,4,5,6,1,3]; iteration 3 (key = 6) → unchanged. ⚠️ Note: options (a) and (c) are identical in the export — a typo in the source; the answer itself is unambiguous.
Q13. A = [−5,−2,−8,−1,−6]; maximum contiguous subarray sum, non-empty?
a. −2 b. −1 c. 5 d. 0
✅ b — −1. With all-negative values you must take at least one element, and the largest single element is −1. Related: if the empty subarray were allowed the answer would be 0 (Kadane's usually starts at 0), which is exactly the distractor (d); in the real algorithm you initialise best = −∞ (or A[0]) when the subarray must be non-empty.
Q14. Deterministic quick sort always taking the first element as pivot, on a strictly increasing array — total run time?
a. Θ(n log n) b. Θ(n) c. Θ(log n) d. Θ(n²)
✅ d — Θ(n²). Every partition is 0 / n−1 → recurrence T(n)=T(n−1)+Θ(n).
Q15. f(n) = O(n²), g(n) = Ω(n³). Which is necessarily true?
a. f = Θ(g) b. g = O(f) c. f = o(g) d. f = Ω(g)
✅ c — f = o(g). f grows at most quadratically, g at least cubically, so f/g → 0. Related: this is the one case where the two bounds combine into a strict relation rather than just O/Ω.
Q16. Divide-and-conquer maximum subarray — which statement is correct?
a. Avoids recursively solving either half b. Any subarray crossing the midpoint is a suffix of the left half plus a prefix of the right half c. Every maximum subarray must contain the first element d. The two halves must contain equal numbers of positive elements
✅ b — the key structural fact that makes the crossing case solvable in linear time.
Q17. D&C maximum subarray can be correct considering only the best subarray wholly in the left half and wholly in the right half.
✅ False — it must also consider the crossing subarray. That omission is the classic wrong solution.
Q18. Ascending array with many duplicates — which statement about binary search is correct?
a. Can find an occurrence, but extra logic may be needed for the first one b. Always returns the first occurrence c. Invalid with duplicates d. Becomes O(n)
✅ a. Standard binary search lands on some duplicate; the leftmost variant needs the "keep searching left" rule.
Q19. An algorithm with Θ(n log n) run time necessarily takes exactly twice as long when n doubles.
✅ False — asymptotics ignore constants and lower-order terms. Doubling n multiplies the work by (2n·log 2n)/(n log n) = 2·(log 2n / log n) > 2, but not exactly 2, and the actual measured time depends on cache effects etc.
Q20. A = [−4, 3, −2, 5, −1, 2, −6, 4]; maximum contiguous subarray sum?
a. 6 b. 8 c. 5 d. 7
✅ d — 7. The subarray [3, −2, 5, −1, 2] sums to 7. Related: the tempting 5 is from [3,−2,5]; −6 breaks any run reaching the final 4.
Q21. Which statement correctly compares the standard maximum-subarray algorithms?
a. Brute force and D&C both Θ(n) b. The standard D&C algorithm is Θ(n log n) c. Kadane's is Θ(n²) d. D&C is always Θ(n²)
✅ b. Kadane's is Θ(n) (the optimal); brute force is Θ(n³) naive or Θ(n²) with prefix sums.
Q22. Apply the Master Theorem to T(n) = 4T(n/2) + n.
a. Θ(n) b. Θ(n log n) c. Θ(n²) d. Θ(n³)
✅ c — Θ(n²). a=4, b=2 → n^(log₂4) = n², which dominates the f(n)=n term (case 1).
Q23. For f(n) = 7n³ + 4n² + 100:
a. Θ(n²) b. Θ(n⁴) c. Θ(n³) d. Θ(2ⁿ)
✅ c — Θ(n³) — the highest-order term dominates.
Q24. Which change to standard merge sort would destroy its stability?
a. Copying the left half before merging b. Taking from the right run when the two current elements are equal c. Using recursion instead of iteration d. Splitting an odd array into unequal halves
✅ b. On a tie you must take the left element; taking the right one reverses the relative order of equal keys.
Q25. Solve T(n) = 2T(n/2) + n, T(1) = Θ(1).
a. Θ(n log n) b. Θ(log n) c. Θ(n²) d. Θ(n)
✅ a — Θ(n log n) (Master Theorem case 2, or the recursion tree: n per level × log n levels).