A.1.1.1: Binary Search
Learning Objectives
Understand conceptually how binary search works
Know how to implement binary search in code
Introduction
Binary search allows us to search a sorted array for a target number in O(logn)
time. The following videos explain the concept.
Example Code
Consider the following canonical binary search implementation.
Exercises
After attempting each problem, find solutions in the Leaderboard tab (HackerRank, may be on left side of page) or Solution or Discuss tabs (LeetCode) on that problem's page. If you get stuck for more than 15 minutes, review and understand the solutions and move on. Come back and re-attempt the problem after a few days.
Pre-Class
Binary Search (LeetCode)
Rocket solution code (Python)
Rocket solution video (Python)
Part 1
First Bad Version (LeetCode)
Valid Perfect Square (LeetCode)
Search Insert Position (LeetCode)
Two Sum II Input Array is Sorted (LeetCode)
Count Negative Numbers in a Sorted Matrix (LeetCode)
Rocket solution code (Python)
Rocket solution video (Python)