Searching for the Smallest Values
This section will explore how to find the index of the smallest items in an unsorted list using three quite different algorithms. We’ll go through a top-down design using each approach.
To start, suppose we have data showing the number of humpback whales sighted off the coast of British Columbia over the past ten years:
|
809 |
834 |
477 |
478 |
307 |
122 |
96 |
102 |
324 |
476 |
The first value, 809, represents the number of sightings ten years ago; the last one, 476, represents the number of sightings last year.
We want to know how changes in fishing practices have impacted the whales’ numbers. Our first question is, what was the lowest number of sightings during those years? This code tells ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access