Mathematics I / Arrays and Lists
Practice question · Match the pairs

Match each array operation to what it does.

  • Access a[i]
  • Length
  • Traverse
  • Out of bounds
  • Reads the element at position i directly
  • Visits every element in turn, usually with a loop
  • Reports how many elements the list holds
  • Uses an index outside 0 to n-1
Hints
  1. One of these is not an operation but an error.
  2. One is constant-time; one costs a pass over everything.
Show the answer
  • Access a[i] Reads the element at position i directly
  • Length Reports how many elements the list holds
  • Traverse Visits every element in turn, usually with a loop
  • Out of bounds Uses an index outside 0 to n-1
Why

Indexed access is direct and cheap; traversal costs a full pass. Length and the last valid index differ by one, and mixing them up is precisely what produces the out-of-bounds error.

Read the lesson: Arrays and Lists →

Practise Arrays and Lists

The app has 5 more questions on this lesson, and keeps your place in the course. Mathematics I is free to start.

More questions on Arrays and Lists