August 2020
Intermediate to advanced
508 pages
11h 53m
English
These are the solutions to the exercises found in the section, Exercises.
Linear search on this array would take four steps. We start at the beginning of the array and check each element from left to right. Because the 8 is the fourth number, we’ll find it in four steps.
Binary search would take just one step in this case. We start the binary search at the middlemost element, and the 8 just happens to be the middlemost element!
To solve this, we need to count how many times we halve 100,000 until we get down to 1. If we keep dividing 100,000 by 2, we see that it takes us 16 times until we get down to about 1.53.
This means a worst-case scenario would take about 16 times.
Read now
Unlock full access