5/39
Part 1 of 7 · Nodes and costsLearn and do

A linked list has no index, so the k-th node is k steps from the head

A Python list jumps to any slot. A linked list has to walk there.

A Python list finds slot 3 directly: xs[3] is one read
xs
0123431415
A linked list follows next from the head, 3 times
3head
→
11 step
→
42 steps
→
13 steps
→
5
→None

Reading the item at position n // 2, median of 5 runs:

Predict

Reading the middle item of a million-item linked list took 8.5 ms. About how long did xs[k] take on a Python list?

Pick an answer above to see the rest