Traversal and Search
Step 1 of 11
hops0
head
node
·
4•
·
8•
·
15•
∅
Traversal is one pointer and one rule: keep reassigning it to node.next until it falls off the end.
The Idea
Traversal means parking a pointer on the head and reassigning it to current.next until it falls off the end. Searching is traversal with a comparison inside. Both are O(n), and neither can skip ahead.
Real-World Example
A museum audio tour numbers its stations, but each recording only ends with "now walk to the next stop." There is no map in your hand, so hearing station twelve means standing through the eleven before it, in order.
The Code
Your turn
Put the steps in the right order.
- Move current on to current.next
- Point current at the head node
- Compare current.value with the target
- Stop once current is None and report a miss
Mini quiz
1 / 3