Track 16 · Lesson 2 of 12
Linear and binary search
Find items by checking each one in turn, or by halving a sorted list again and again, and use the bisect module for sorted data.
You will be able to
- Write a linear search that returns the position of the first match or -1
- Explain why binary search needs sorted data and how it halves the search range
- Implement an iterative binary search without off-by-one errors
- Use bisect_left and bisect_right to find positions and count values in a range
Included with a Formula Quest membership
It has 4 graded exercises with feedback, hints and solutions. Python Quest is included in Formula Quest memberships that cover Python; membership and billing are managed on Formula Quest.
View Formula Quest memberships
Tracks 1 and 2, the first lesson of every track, the playground and the dataset library are free.