BITS Pilani
BITS Logo
CS G526: Advanced Algorithms and Complexity

Randomized Data Structures: Skip Lists

Lecture 11 |2026-08-31
Tulasimohan Molli
BITS Pilani, Hyderabad Campus

Agenda

  1. Linked Lists & The Search Bottleneck
  2. Skip List Structure & Intuition
  3. Operations: Search, Insert, and Delete
  4. Analysis: Expected Height & Search Time

The Dynamic Set Problem: Linked Lists

Goal: Maintain an ordered set S supporting Search, Insert, and Delete.

Head 12 25 42 NULL Key Pointer (Next) Node
  • Pointers & Node: Each node stores a Key (value) and a Pointer (next memory address).
  • Pointer Splicing (O(1)): Inserting/deleting is just rewiring 1–2 pointer addresses—no moving data in memory.

Linked Lists: Operations & The Bottleneck

Operation Sorted List Cost
Search(k) \Theta(n)
Insert(x) \Theta(n)
Delete(x) \Theta(n)
  • The Core Bottleneck: Without random access, we cannot jump to the median \implies Binary Search fails.
  • The Design Question: Can we add shortcut pointers to achieve O(\log n) search without losing O(1) dynamic splicing?

The Search Structure Dilemma

How do we maintain a set of ordered elements supporting search, insertion, and deletion in O(\log n) time?

  • Deterministic Solutions: AVL trees, Red-Black trees, Splay trees.
    • Drawbacks: Highly complex rebalancing logic, rotations, and pointer modifications on insertion/deletion.
  • Randomized Alternative: Skip Lists (William Pugh, 1990).
    • Features: Easy to implement, no rebalancing logic, expected O(\log n) operations with high probability.

Skip List Structure

A skip list is a hierarchy of ordered linked lists.

  • Level 0 (L_0): Standard sorted linked list containing all elements, starting at -\infty and ending at +\infty.
  • Level i (L_i): A subset of elements from L_{i-1}, promoted independently by tossing a fair coin (probability p = 1/2).
  • Pointers: Each node has a forward pointer (next) and a down pointer (below) to the level underneath.

Skip List Visualized

A search hops horizontally on express lanes, dropping down when the next key exceeds target:

L3 -∞ 30 +∞ L2 -∞ 15 30 45 +∞ L1 -∞ 10 15 25 30 45 55 +∞ L0 -∞ 5 10 15 20 25 30 38 45 50 55 +∞ Search(25) Found!

Skip List Operations

  • 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.
  • Key Advantage: No tree rotations, color-flipping, or complex balancing invariants required!

Expected Height Analysis

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.

Search Time: Backward Analysis

Trace the search path backwards from target key in L_0 up to the start:

  • Backward Step Rule (at node v):
    • Promoted (prob 1/2): Step Up (h-1 levels remain to climb).
    • Not promoted (prob 1/2): Step Left (h levels remain to climb).
  • 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)}.

Space Complexity

Is the pointer overhead too large compared to balanced binary trees?

  • Expected Node Height: \mathbb{E}[\text{height}(v)] = \sum_{j=1}^{\infty} (1/2)^j = 1.
  • Expected Pointers: 1/p = 2 pointers per node on average.
  • Total Memory: 2n = \mathbf{O(n)} total pointers across the entire structure.
  • Efficiency: Simpler than AVL/Red-Black trees which require parent pointers, color/balance bits, and rotation metadata at every node.

Concept Check

  • Q1: If coin flip probability is p = 1/4, what is the expected number of pointers per node?
    Answer: 1/p = \mathbf{4} pointers per node 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.

Next Lecture

Hash Tables & Universal Hashing — collision rates, pairwise independence, and universal hash families.