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
- Picture the elements laid out in consecutive memory slots.
- 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.
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.