Physics I / Lists, arrays, and structured storage
Practice question · Multiple choice

Appending to the end of a list is cheap; inserting at the front is expensive. What about the storage layout causes the asymmetry?

Hints
  1. Picture the elements laid out in consecutive memory slots.
  2. What has to move to make room at position 0?
Show the answer

A. Contiguous storage: an insertion at the front shifts everything

Why

Cost follows layout. This is exactly why a deque or linked list exists, different layouts make different operations cheap, and the choice of structure is a choice about which operations you will do most.

Read the lesson: Lists, arrays, and structured storage →

Practise Lists, arrays, and structured storage

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

More questions on Lists, arrays, and structured storage