O'Reilly logo

A Common-Sense Guide to Data Structures and Algorithms by Jay Wengrow

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Insertion

The efficiency of inserting a new piece of data inside an array depends on where inside the array you’d like to insert it.

Let’s say we wanted to add "figs" to the very end of our shopping list. Such an insertion takes just one step. As we’ve seen earlier, the computer knows which memory address the array begins at. Now, the computer also knows how many elements the array currently contains, so it can calculate which memory address it needs to add the new element to, and can do so in one step. See the following diagram:

images/chapter2/understanding_arrays_Part10.png

Inserting a new piece of data at the beginning or the middle of an array, however, is a different story. In these cases, ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required