Worst-Case and Average-Case Analysis · Short answer · 2 marks
Solve for , with , by unrolling. Give the closed form and its class.
Unrolling times gives . Taking gives , which is .
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 · Problem · 4 marks
Let keys be hashed independently and uniformly into a table with slots (simple uniform hashing). Let be the number of pairs of keys that hash to the same slot.
For let if keys and collide and otherwise. Find and use linearity of expectation to find in terms of and . [2]
For keys, what is the smallest integer for which ? [1]
For that , use Markov’s inequality to give a lower bound on the probability that no two of the keys collide. [1]
Given where key goes, key lands in the same slot with probability , so . There are pairs and , hence .
, so we need , i.e. . The smallest integer is .
Markov: (it is ). So .
Randomized Algorithms and Quicksort · Short answer · 2 marks
Randomized quicksort sorts distinct keys. Out of the pairs of keys, what is the expected number of pairs that are never compared with each other? Give an exact fraction.
. A pair at distance is compared with probability . The numbers of pairs at distance are , so the expected number of compared pairs is , and the expected number of pairs never compared is .
Minimum Spanning Trees and Lower Bounds · Multiple choice · 1 mark
A sorted array holds distinct keys. An algorithm locates a query using only yes/no questions of the form “is ?” and must report which of the gaps (before , between neighbours, after ) contains . What does the decision-tree argument give as a lower bound on the worst-case number of questions?
Answer: (B)
A binary tree with distinct possible answers needs at least leaves, so its height is at least (binary search achieves ). The value rounds down and leaves cannot cover all gaps. doubles the bound for no reason and is the cost of a linear scan.
Algorithms and Data Structures · University of Waterloo (Waterloo, UWaterloo, UW) · also written ECE250
Make a free, printable ECE 250 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 350 original questions and skips the ones you have already seen.
Start with the past exams and tests your instructor or the Waterloo library shares: they show what your course actually asks. Most courses only have a few, so once you have worked through them, make fresh ECE 250 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 University of Waterloo. Course codes only say which topics a paper covers; papers are original practice material, not past or upcoming exams.