Worst-Case and Average-Case Analysis · Short answer · 3 marks
The array holds distinct keys in uniformly random order. A descent is an index with . What is the expected number of descents? Justify with indicator variables, and evaluate it for .
Let if . For two distinct keys in random order, either one is larger than the other with probability , so . By linearity of expectation, ; for this is . (The are not independent, but linearity does not need independence.)
Balanced and Augmented Search Trees · Multiple choice · 2 marks
Let be the fewest nodes in an AVL tree of height (an empty tree has height , a single node height ). What is the greatest possible height of an AVL tree with exactly 20 nodes?
Answer: (B)
with , gives . A tree of height 5 needs at least nodes, so it can be built with exactly 20; height 6 needs at least 33. The answer 4 is , the least possible height; 6 comes from applying the bound as if it were exact, and 7 from rounding that bound up.
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.
Amortized Analysis · Multiple choice · 1 mark
A queue is built from two stacks, and . Enqueue() pushes onto . Dequeue first checks : if it is empty, it pops every element of and pushes each onto ; then it pops and returns the top of . Counting each push and each pop as one primitive operation, how many primitive operations are performed on a given element from its Enqueue until the Dequeue that returns it?
Answer: (C)
Every element is pushed onto , later popped from and pushed onto during a transfer (it cannot be returned directly from ), and finally popped from : four primitives, always. This constant per-element cost is why operations cost in total even though one Dequeue can cost . Only counting the push and the final pop gives .
Minimum Spanning Trees and Lower Bounds · Short answer · 2 marks
Every edge of the complete graph has weight . How many different minimum spanning trees does it have? Justify by counting the possible shapes.
Every spanning tree has edges and weight , so all spanning trees are minimum. A tree on labelled vertices is either a star ( choices of the centre) or a path ( distinct paths, since a path and its reverse coincide). In all there are minimum spanning trees.
Data Structures · University of Illinois Urbana-Champaign (UIUC, Illinois, U of I) · also written CS225
Make a free, printable CS 225 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 500 original questions and skips the ones you have already seen.
Start with the past exams and tests your instructor or the UIUC library shares: they show what your course actually asks. Most courses only have a few, so once you have worked through them, make fresh CS 225 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 Illinois Urbana-Champaign. Course codes only say which topics a paper covers; papers are original practice material, not past or upcoming exams.