DAA Study Hub

Mock midterm A (exam mode)

75 minutes, 50 marks, closed book. Answers stay folded until the timer rings.

How to use exam mode

  1. Get paper and a pen, then set a 75-minute timer on your phone. Closed book: no notes, no cheatsheet, no other tabs.
  2. Every answer below is folded shut. Don't open any until the timer rings.
  3. Mark yourself with the answers. Copy every mistake into My mistakes and write the score with the Log my score form at the bottom of this page.
  4. Two days later, redo only the questions you missed. Then try Paper B.

The questions mix all topics, the way an exam might. They are new problems written for practice, not copies of slide or book exercises.

Total: 50 marks


Q1. Warm-up (6 marks)

(a) Simplify log⁡2(32n4)\log_2(32n^4). [2]

(b) Give a closed form for ∑i=1n(4i+1)\sum_{i=1}^{n}(4i + 1). [2]

(c) Evaluate 1+3+9+27+811 + 3 + 9 + 27 + 81 using the geometric-series formula. [2]

Q2. Counting steps (6 marks)

for i ← 1 to n do
    for j ← i to n do
        for k ← 1 to 10 do
            x ← x + 1

(a) Exactly how many times does x ← x + 1 run? [3]

(b) Give the Θ bound and explain the role of the k loop. [3]

Q3. Asymptotic proofs (10 marks)

(a) Prove 6n2+4n−10=Θ(n2)6n^2 + 4n - 10 = \Theta(n^2) with explicit c1,c2,n0c_1, c_2, n_0. [5]

(b) Rank from slowest- to fastest-growing: n1.5n^{1.5}, nlog⁡nn\log n, 2n/22^{n/2}, log⁡(n2)\log(n^2), n\sqrt n. [5]

Q4. Insertion sort (8 marks)

(a) Trace insertion sort on [6, 2, 8, 1, 4]. Show the array after each outer iteration and count the shifts. [4]

(b) State the loop invariant and explain the maintenance step in your own words. [4]

Q5. Correctness (6 marks)

CountEven(A, n)
1  c ← 0
2  for i ← 1 to n do
3      if A[i] mod 2 = 0 then c ← c + 1
4  return c

State a loop invariant and prove initialization, maintenance and termination.

Q6. Induction (6 marks)

Prove for all n≥1n \ge 1: ∑i=1ni⋅2i=(n−1)2n+1+2\sum_{i=1}^{n} i\cdot 2^{i} = (n - 1)2^{n+1} + 2.

Q7. Merge sort & recurrences (8 marks)

(a) Show the merge of [3, 5, 9] and [2, 4, 10, 11]. How many comparisons? [2]

(b) Solve T(n)=3T(n/2)+nT(n) = 3T(n/2) + n with a recursion tree: give the level table and the Θ answer. [4]

(c) Solve T(n)=T(n/3)+1T(n) = T(n/3) + 1. [2]


Score bands: 45+ ready · 35–44 review your mistakes · below 35 redo the weakest topics in a different study mode.

Log my score

Marked yourself? Save the score to My progress (stays in this browser).

A

On this page