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

Searching

As we stated previously, searching an array is looking to see whether a particular value exists within an array and if so, which index it’s located at. Let’s see how many steps the search operation takes for an array if we were to search for "dates".

When you and I look at the shopping list, our eyes immediately spot the "dates", and we can quickly count in our heads that it’s at index 3. However, a computer doesn’t have eyes, and needs to make its way through the array step by step.

To search for a value within an array, the computer starts at index 0, checks the value, and if it doesn’t find what it’s looking for, moves on to the next index. It does this until it finds the value it’s seeking.

The following diagrams demonstrate this ...

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