Sample SFWRENG 2C03 questions
  1. Worst-Case and Average-Case Analysis · Short answer · 2 marks

    Prove from the definition that n2∉O(n)n^2\notin O(n).

    Show solution

    Suppose n2≤c nn^2\le c\,n for all n≥n0n\ge n_0, for some constants c,n0c,n_0. Dividing by n>0n>0 gives n≤cn\le c for all n≥n0n\ge n_0. But n=max⁡(n0,⌈c⌉+1)n=\max(n_0,\lceil c\rceil+1) violates this, a contradiction.

  2. Balanced and Augmented Search Trees · Multiple choice · 2 marks

    Which statement about the number of rotations in an AVL tree with nn keys is correct?

    1. Both insertion and deletion need at most one single or double rotation, because the heights of subtrees change by at most 1

    2. Insertion can need a rotation at every level of the search path, while deletion needs at most one

    3. Both insertion and deletion can need a rotation at every level, because a height change can travel to the root

    4. Insertion needs at most one single or double rotation; deletion can need a rotation at each of Θ(log⁡n)\Theta(\log n) levels

    Show solution

    Answer: (D)

    After an insertion, the first unbalanced node on the way up is repaired by a single or double rotation that restores the subtree to its height before the insertion, so no ancestor above it changes height: at most one restructuring. A deletion can leave the repaired subtree one level shorter than before, so the imbalance can reappear at the next ancestor, and so on up to the root (a Fibonacci-shaped tree with one leaf removed does this).

  3. Hashing · Multiple choice · 1 mark

    Four keys are hashed independently and uniformly into a table with m=2m=2 slots. Call a key shared if at least one other key hashes to the same slot. What is the expected number of shared keys?

    1. 22

    2. 33

    3. 3.53.5

    4. 44

    Show solution

    Answer: (C)

    (C). A given key is not shared only if the other three keys all go to the other slot: probability (1/2)3=1/8(1/2)^3=1/8. So it is shared with probability 7/87/8, and by linearity of expectation the expected number of shared keys is 4⋅7/8=3.54\cdot 7/8=3.5. The value 3=(42)/23=\binom42/2 is the expected number of colliding pairs, 2=n/m2=n/m is the load factor, and 44 would need every key shared in every outcome, which fails when the keys split 11–33 between the slots.

  4. Randomized Algorithms and Quicksort · Graph · 3 marks

    Randomized quicksort sorts five distinct keys z1<z2<⋯<z5z_1<z_2<\dots<z_5. Fill the upper triangle of the table with Pr⁡[zi and zj are ever compared]\Pr[z_i \text{ and } z_j \text{ are ever compared}] for i<ji<j, as exact fractions, and then give the sum of all ten entries.

    z1z_1z2z_2z3z_3z4z_4z5z_5
    z1z_1–            
    z2z_2–         
    z3z_3–      
    z4z_4–   
    z5z_5–

    Sum of the ten entries:    

    Show solution

    Answer: 1; 23\frac23; 12\frac12; 25\frac25; 1; 23\frac23; 12\frac12; 1; 23\frac23; 1; 375\frac{37}{5}

    Each entry is 2j−i+1\frac{2}{j-i+1}: the keys zi,zjz_i,z_j meet iff the first pivot among zi,…,zjz_i,\dots,z_j is one of them. The sum is the expected number of comparisons, 4⋅1+3⋅23+2⋅12+1⋅25=3754\cdot1+3\cdot\frac23+2\cdot\frac12+1\cdot\frac25=\frac{37}{5}.

  5. Minimum Spanning Trees and Lower Bounds · Short answer · 2 marks

    Prim’s algorithm runs on a connected graph with nn vertices and mm edges, using a binary min-heap with all vertices in it at the start. For each of Extract-Min and Decrease-Key, give the number of calls (exact for the first, the best simple upper bound for the second) and then the resulting worst-case running time.

    Show solution

    Extract-Min is called exactly nn times. Decrease-Key is called at most once per edge, at most mm times (an edge {u,v}\{u,v\} can only lower a key when the first of u,vu,v is extracted, because the other is still in the heap; later it is no longer). Each call costs O(log⁡n)O(\log n), so the running time is O((n+m)log⁡n)=O(mlog⁡n)O((n+m)\log n)=O(m\log n) because m≥n−1m\ge n-1 in a connected graph. (A bound of 2m2m decrease calls, one per edge direction, is also acceptable.)

About SFWRENG 2C03 practice exams

SFWRENG 2C03 practice exams

Data Structures and Algorithms · McMaster University (McMaster, Mac, MacU) · also written SFWRENG2C03

Make a free, printable SFWRENG 2C03 practice exam: choose the topics, the length and the difficulty above, and get an exam-style PDF with a full answer key. Each paper draws on 300 original questions and skips the ones you have already seen.

Looking for SFWRENG 2C03 past exams?

Start with the past exams and tests your instructor or the McMaster library shares: they show what your course actually asks. Most courses only have a few, so once you have worked through them, make fresh SFWRENG 2C03 practice exams here on the same topics, with full answer keys, as many as you need. The questions here are original, not copies of past exams.

Topics covered

  • Worst-Case and Average-Case Analysis · 50 questions
  • Balanced and Augmented Search Trees · 50 questions
  • Hashing · 50 questions
  • Randomized Algorithms and Quicksort · 50 questions
  • Graphs, BFS and DFS · 50 questions
  • Minimum Spanning Trees and Lower Bounds · 50 questions

More McMaster courses

questionbank.dev is independent and not affiliated with McMaster University. Course codes only say which topics a paper covers; papers are original practice material, not past or upcoming exams.