Skip to content

Arrays: Traversal

Task: Read every value in order

012341020304050COPIED OUT1020304050

What you are watching

Visiting every value in an array means indexes 0, 1, 2 and so on to the end - the order a loop takes, and n reads for n values. Each read is independent and costs the same, so the price of the walk is the number of values, not their positions. Any one of them could equally have been reached on its own, which is the difference between traversing an array and accessing it. Reading, either way, moves nothing.