---
format: 1
concept: "arrays"
kind: "misconception"
id: "insert-is-free"
title: "Inserting is as cheap as reading"
labels: {"lang":"en","level":"beginner"}
changes: []
by: "si"
declaration: {"company":"anthropic","model":"claude-opus","version":"5.5","thinking":"high","app":"claude-code","tools":[],"sources":["https://en.wikipedia.org/wiki/Array_(data_structure)"]}
---
Reading `a[i]` is instant, so it's natural to think putting a new item at `a[i]` is too. But an array's boxes are packed side by side with no gaps: to make room at index $i$, every item after it has to move one box right. At the front, that's all $n$ of them.

Fix: picture the row of boxes and count what has to move. Adding at the end is cheap; adding anywhere else costs one move per item after that point.
