Practice Searching in CS Thinking

Use these practice problems to test your method after reviewing the concept explanation and worked examples.

Quick Recap

The process of locating a specific item or value within a collection of data using a systematic strategy.

Looking for a book on a shelf, a name in a list, a file on your computer.

Example 1

medium
Use linear search to find the value 7 in the list [3, 9, 7, 1, 5]. How many comparisons are needed?

Example 2

medium
Use binary search to find 23 in the sorted list [5, 10, 15, 20, 23, 30, 35]. Show each step.

Example 3

medium
Can binary search be used on the unsorted list [8, 2, 5, 1, 9]? Why or why not?

Example 4

hard
A sorted list has 128 elements. In the worst case, about how many comparisons does binary search need, and how does that compare with linear search?