📚 Drozdek (Ch. 3)
How efficient is a linked list?
Recall how the binary search algorithm removed the complexity from searching an (ordered) array…
What if we could do some kind of non-sequential search on a linked list?
A special kind of linked list that allows just such a search is called a skip list .
By making different nodes hold different numbers of pointers, you can search non-sequentially:
Perfect Skip List
Perfect Skip List
The “level” of a node refers to the number of pointers it has. The highest level is given by \(\lg(n) + 1\) (1-indexed), or \(\lg(n)\) (0-indexed).
Skip List Levels
Skip List Search
This “perfect skip list” is easy to draw… but difficult (expensive) to achieve in practice.
Consider adding a new item / removing an item.
Skip List Search
Nodes do not have to be perfectly distributed…
As long as the requirements are met for the number of nodes at each level, the skip list can still work.
Imperfect Skip List
The new node can determine its number of links at random, provided that it uses a probability distribution that (in the long run) maintains the correct proportions of levels…
Imperfect Skip List
Keep a special “node” that points “back” at all “see-able” nodes… those you used to find the insertion point.
Use that backLook node to set the appropriate next pointers.
backLook Node
Searching: ?
Insert (random): ?
Space: ?
Imperfect Skip List
Searching: \(O(\log_2(n))\)
Insert (random): ?
Space: ?
Imperfect Skip List
Searching: \(O(\log_2(n))\)
Insert (random): \(O(\log_2(n))\)
Space: ?
Imperfect Skip List
Searching: \(O(\log_2(n))\)
Insert (random): \(O(\log_2(n))\)
Space: \(O(n \cdot \log_2(n))\)

Skip Lists

CS 50x2 Accelerated Programming Series