Binary search algorithm interview questions

Ship capacity problem

There are some problems which do not appear to be a binary search problem at first. For example, ship capacity problem on leetcode. Problem statement is: A conveyor belt has ...
Read More

Keep an eye on the binary search algorithm

What is binary search algorithm A classic example of the application of the binary search algorithm is searching for a word in a dictionary, or when you open a page ...
Read More

Number of occurrences of element

Number of occurrences of element Given a sorted array and a key, find the number of occurrences of a key in that array. For example, in the below array, the ...
Read More

Last occurrence element in array

Finding the last occurrence of an element in a list of numbers is very similar to the First occurrence of an element with binary search. Given a sorted array and ...
Read More

First occurrence of element with binary search

First occurrence of element in sorted array Given a sorted array and an element, find the first occurrence of key in array.  As array can contain duplicate values, there can ...
Read More

Minimum number of pages to read

Minimum number of pages to read In previous post Ceiling in sorted array using binary search , we understood a very important concept about application of binary search in problems where minimum ...
Read More

Ceiling in sorted array using binary search

Ceiling in sorted array In last post, binary search algorithm, we discussed basics of algorithm, it's implementation and worst case complexity. Today, we will use binary search algorithm to solve another ...
Read More

Binary search algorithm

Binary search algorithm The binary search algorithm is a very known algorithm and taught in the basics of computer science algorithm class. It is simple algorithm however, it is very ...
Read More

Longest Increasing Subsequence in O(nlogn)

In the last post, longest increasing subsequence, we discussed brute force and dynamic programming based solutions. The complexity of the brute force solution is exponential whereas for the dynamic programming ...
Read More