Goal: Maintain an ordered set S supporting Search, Insert, and Delete.
next memory address).| Operation | Sorted List Cost |
|---|---|
Search(k) |
\Theta(n) |
Insert(x) |
\Theta(n) |
Delete(x) |
\Theta(n) |
How do we maintain a set of ordered elements supporting search, insertion, and deletion in O(\log n) time?
A skip list is a hierarchy of ordered linked lists.
next) and a down pointer (below) to the level underneath.A search hops horizontally on express lanes, dropping down when the next key exceeds target:
Search(k): Start at top-left sentinel. Walk right while \text{next} \le k; drop down to L_{i-1} when \text{next} > k. Repeat until found or reaching L_0.Insert(k): Run Search(k) to find position in L_0. Repeatedly flip a fair coin: if Heads, promote k to L_{i+1}; if Tails, stop.Delete(k): Search for k and unlink it from all levels where it appears via standard O(1) pointer rewiring.What is the expected maximum level of a skip list on n elements?
Single Node Height H_v: \Pr(H_v \ge h) = (1/2)^h (geometric distribution).
Max Height H = \max_v H_v across all n nodes.
Union Bound: Probability that any node exceeds level c \log_2 n: \Pr(H \ge c \log_2 n) \le \sum_{v=1}^n \Pr(H_v \ge c \log_2 n) \le n \cdot (1/2)^{c \log_2 n} = n^{1-c}
High Probability: For c = 3, \Pr(H \ge 3 \log_2 n) \le 1/n^2 \implies \mathbf{O(\log n)} whp.
Trace the search path backwards from target key in L_0 up to the start:
Backward Step Rule (at node v):
Cost Recurrence: Expected steps C(h) to climb h levels: C(h) = 1 + \frac{1}{2} C(h-1) + \frac{1}{2} C(h) \implies C(h) = 2 + C(h-1)
Closed Form (C(0) = 0): \mathbf{C(h) = 2h} \implies \mathbb{E}[\text{Search Steps}] \le 2 \cdot \mathbb{E}[H] = \mathbf{O(\log n)}.
Is the pointer overhead too large compared to balanced binary trees?
Q1: If the promotion probability is p = 1/4, what is the expected height (or number of levels) of an element in the skip list?
Answer: 1/p = \mathbf{4} levels on average.
Q2: Why is backward analysis preferred over forward analysis?
Answer: Forward paths depend on global structure, while backward steps form a simple, memoryless coin-flipping recurrence at each step.
Hash Tables & Universal Hashing — collision rates, pairwise independence, and universal hash families.
CS G526: Advanced Algorithms & ComplexityTulasimohan Molli