Welcome to Interviewbit, help us create the best experience for you!

Currently, You are a:

Few details about your education

College/University *
Enter the name of your college
Branch *
Year of completion *

Few details about your education

College/University *
Enter the name of your college
Branch *
Year of completion *

Few details about your career...

Current Company *
Enter company name
Experience *

You're all set!

Begin your success journey!

Sign Up using
Full name *
Email *
Password *

By creating an account, I acknowledge that I have read and agree to InterviewBit’s Terms and Privacy Policy .

Welcome back!

Log In using
Email *
Password *

Level 3

Binary Search

Binary search is the most efficient searching algorithm having a run-time complexity of O(log2 N). This algorithm works only on a sorted list of elements.

Binary search begins by comparing the middle element of the list with the target element. If the target value matches the middle element, its position in the list is returned. If it does not match, the list is divided into two halves. The first half consists of the first element to middle element whereas the second half consists of the element next to the middle element to the last element. 

Let's take an example and see how binary search works and number of steps it takes as compared to linear search.

 

Binary Search example

Important tutorials

1. Binary Search Implementations And Common Errors
View Tutorial
2. Beyond Sorted Array Binary Search
View Tutorial

Serious about Learning Programming ?

Learn this and a lot more with Scaler Academy's industry vetted curriculum. Attend a Free Live Class today!

Binary Search Problems

Simple binary search
Problem Score Companies Time Status
Search in Bitonic Array! 100 49:40
Smaller or equal elements 200
30:44
WoodCutting Made Easy! 200 53:59
Matrix Search 250
36:51
Search for a Range 250
42:02
Sorted Insert Position 250
25:03
Search answer
Problem Score Companies Time Status
Matrix Median 225 77:24
Square Root of Integer 275 40:32
Allocate Books 350
67:57
Painter's Partition Problem 350 81:37
Red Zone 400
45:16
Search step simulation
Problem Score Companies Time Status
Implement Power Function 275
59:44
Simple Queries 300
61:40
Sort modification
Problem Score Companies Time Status
Median of Array 325 86:41
Rotated Sorted Array Search 325 56:53

Additional Practice

Problem Score Companies Time Status
Capacity To Ship Packages Within B Days 300 40:43