Randomized and Range-Query Clinic
Retrieval Prompts
- Explain why a skip list's expected height is
O(log n)without computing the constant. - Define a treap's two invariants: BST on keys and heap on priorities.
- State the Bloom filter guarantee in both directions (positives and negatives).
- Write the formulas for optimal bit count
mand hash countkgivennand target false-positive ratep. - Explain the role of the segment tree's lazy-propagation array.
- Explain how a Fenwick tree recovers prefix sums using the low-bit trick.
Compare and Distinguish
Separate these pairs clearly:
- skip list vs treap (where the randomness lives: in the levels vs in the priorities)
- Bloom filter vs hash set (why Bloom saves memory and what it gives up)
- segment tree vs Fenwick tree (what operations each supports; where segment trees win)
- point update with range query vs range update with point query (how Fenwick covers both cases with one trick)
- path copying vs fat nodes (two ways to get persistence; which generalizes to arbitrary DAGs)
Common Mistake Check
For each statement, identify the error:
- "A Bloom filter can return a false negative if two elements hash to the same slot."
- "A segment tree uses exactly
2nnodes." - "A Fenwick tree supports arbitrary range-min queries."
- "A persistent list must copy the entire list on every update."
- "Adding more hash functions to a Bloom filter always reduces the false-positive rate."
Mini Application
Part A - Bloom filter sizing
Design a Bloom filter for the following constraints, and show your work:
n = 10^6keys, target false-positive ratep = 0.01n = 10^8keys, target false-positive ratep = 0.001n = 10^4keys, bit budget fixed atm = 100,000(find achievablepand optimalk)
Use m = -n * ln(p) / (ln 2)^2 and k = (m/n) * ln 2, rounding to sensible integers.
Part B - Segment tree derivation
Given an array of length n = 8 and the recursive segment-tree build, answer:
- how many leaves, internal nodes, and total nodes
- for a point update at index 3, which nodes get touched
- for a range query
sum[2..6], which nodes' values are combined - sketch the lazy-propagation path for a range update
add 5 to [1..4]
Part C - Persistent structure
Given a persistent BST with versions v0, v1, v2 where:
v0 = emptyv1 = insert(5) into v0v2 = insert(3) into v1
Draw the shared node graph. Count how many nodes are physically allocated across all three versions. Explain why full persistence costs O(log n) per operation rather than O(n).
Evidence Check
This page is complete only if you can:
- size a Bloom filter from
nandpwithout looking up the formula - trace point update, range query, and lazy range update on an 8-element segment tree by hand
- compute
lowbit(i)and explain Fenwick index traversal for query and update - describe path copying in a persistent BST and count shared nodes across two versions