Covers IGNOU MCS-208 §Programme guide topic "Skip lists" (not in the Unit 3 booklet)
Searching a sorted linked list is O(n), even though the data is sorted, because we cannot jump to the middle as binary search does in an array. A skip list adds “express lanes” on top of the linked list so that a search can skip over many nodes at once.
The idea
Each node stores its key and an array of forward links, one per level it belongs to. A dummy header node starts every level.
Start at the header on the top level. On each level, move right while the next key is smaller than the search key; then drop down one level. After level 0, the next node either holds the key or the key is not present.
Insertion
Search for the key as above, remembering in update[i] the last node visited on each level i.
Choose the new node’s number of levels at random: start at 1 and keep adding a level while a coin flip comes up heads.
On each of its levels i, link the new node in after update[i] (as in an ordinary singly linked list insertion).
Deletion is the reverse: find update[i] on every level and bypass the node on each level it belongs to.
Cost
Operation
Skip list (expected)
Skip list (worst case)
Sorted linked list
Search
O(logn)
O(n)
O(n)
Insert
O(logn)
O(n)
O(n)
Delete
O(logn)
O(n)
O(n)
Space
O(n) (about 2n links)
O(n⋅L) for at most L levels
O(n)
The worst case happens only if the coin flips are extremely unlucky, which is very unlikely for large n. Skip lists give performance similar to balanced search trees (Unit 7) with much simpler code; they are used, for example, in the Redis database for sorted sets.
Key takeaways
A skip list = sorted linked list (level 0) + sparser express levels above it.
Search: go right while the next key is smaller, then go down a level.
A new node’s height is chosen by coin flips (probability 21 per extra level).
Expected O(logn) search, insert and delete; O(n) expected space.
Practice questions
Answer on paper first, then check. The explanation matters more than the letter you chose.
Question 6 · short answer
Explain how a key is searched for in a skip list, and trace the search for 9 in the example.
Show worked answer
Start at the header on the highest level. On the current level, move forward while the next node’s key is smaller than the search key; when the next key is larger or equal (or there is none), go down one level. After processing level 0, the next node on level 0 holds the key if it is present. Trace for 9: level 3: next is 19, not < 9, go down; level 2: next is 12, go down; level 1: next is 12, go down; level 0: move to 3, 6, 7 (all < 9); next is 9, not < 9, stop. The next node holds 9: found after 3 moves.
MCA Online notes are made for reading on screen. Open https://mcastudy.online/mcs-208/lists/skip-lists/ to read this page.