Reading
The first operation we’ll look at is reading, which looks up what value is contained at a particular index inside the array.
A computer can read from an array in just one step. This is because the computer has the ability to immediately access any particular index in the array and peer inside. In our example of ["apples", "bananas", "cucumbers", "dates", "elderberries"], if we looked up index 2, the computer would jump right to index 2 and report that it contains the value "cucumbers".
How is the computer able to look up an array’s index in just one step? Let’s see how.
A computer’s memory can be viewed as a giant collection of cells. In the following diagram, you can see a grid of cells in which some are empty and some contain bits ...
Get A Common-Sense Guide to Data Structures and Algorithms in JavaScript, Volume 1 now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.