Worst-Case and Average-Case Analysis · Short answer · 2 marks
Prove from the definition that .
Suppose for all , for some constants . Dividing by gives for all . But violates this, a contradiction.
Balanced and Augmented Search Trees · Multiple choice · 2 marks
Which statement about the number of rotations in an AVL tree with keys is correct?
Both insertion and deletion need at most one single or double rotation, because the heights of subtrees change by at most 1
Insertion can need a rotation at every level of the search path, while deletion needs at most one
Both insertion and deletion can need a rotation at every level, because a height change can travel to the root
Insertion needs at most one single or double rotation; deletion can need a rotation at each of levels
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).
Hashing · Multiple choice · 1 mark
Four keys are hashed independently and uniformly into a table with slots. Call a key shared if at least one other key hashes to the same slot. What is the expected number of shared keys?
Answer: (C)
(C). A given key is not shared only if the other three keys all go to the other slot: probability . So it is shared with probability , and by linearity of expectation the expected number of shared keys is . The value is the expected number of colliding pairs, is the load factor, and would need every key shared in every outcome, which fails when the keys split – between the slots.
Randomized Algorithms and Quicksort · Graph · 3 marks
Randomized quicksort sorts five distinct keys . Fill the upper triangle of the table with for , as exact fractions, and then give the sum of all ten entries.
| – | |||||
| – | |||||
| – | |||||
| – | |||||
| – |
Sum of the ten entries:
Answer: 1; ; ; ; 1; ; ; 1; ; 1;
Each entry is : the keys meet iff the first pivot among is one of them. The sum is the expected number of comparisons, .
Minimum Spanning Trees and Lower Bounds · Short answer · 2 marks
Prim’s algorithm runs on a connected graph with vertices and 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.
Extract-Min is called exactly times. Decrease-Key is called at most once per edge, at most times (an edge can only lower a key when the first of is extracted, because the other is still in the heap; later it is no longer). Each call costs , so the running time is because in a connected graph. (A bound of decrease calls, one per edge direction, is also acceptable.)
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.
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.
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.