Algorithms and Data Structures

Lesson 05 · 15 min

Binary search

How to find an element among a million in twenty steps.

15 minLesson 5 of 8Practice includedAsk AI on any point

In a sorted array you do not have to check everything. Look at the middle: if the target is larger, discard the left half, if it is smaller, the right half. Each step halves the search space, so the complexity is O(log n).

Sign in to continue

The rest of this lesson opens after sign up

The first lesson of every course is open without an account. To read on, solve the practice and use Ask, create a free account or log in.