Skip to content

Tag Archives: Binary Search

A rational is represented as p/qb, for example 2/3. Given a sorted array of rational numbers, how to search an element using Binary Search. Use… Read More
Given an integer x, find it’s square root. If x is not a perfect square, then return floor(√x). Examples : Input: x = 4 Output:… Read More
Given an array of jobs with different time requirements. There are K identical assignees available and we are also given how much time an assignee… Read More
Given a sorted array in which all elements appear twice (one after one) and one element appears only once. Find that element in O(log n)… Read More
Given two sets represented by two arrays, how to check if the given two sets are disjoint or not? It may be assumed that the… Read More
Given a binary array sorted in non-increasing order, count the number of 1’s in it.  Examples:  Input: arr[] = {1, 1, 0, 0, 0, 0,… Read More
Consider the following C implementation of Binary Search function, is there anything wrong in this? // A iterative binary search function. It returns location of… Read More
We can use binary search to reduce the number of comparisons in normal insertion sort. Binary Insertion Sort uses binary search to find the proper… Read More
Given a sorted array arr[] of n elements, write a function to search a given element x in arr[]. A simple approach is to do… Read More
We basically ignore half of the elements just after one comparison. Compare x with the middle element. If x matches with middle element, we return… Read More
A sorted array is rotated at some unknown point, find the minimum element in it. The following solution assumes that all elements are distinct. Examples:  Input:… Read More
Given a function ‘int f(unsigned int x)’ which takes a non-negative integer ‘x’ as input and returns an integer as output. The function is monotonically… Read More
We all aware of binary search algorithm. Binary search is easiest difficult algorithm to get it right. I present some interesting problems that I collected on binary… Read More
Given two sorted arrays, a[] and b[], the task is to find the median of these sorted arrays, in O(log n + log m) time… Read More
Given an unsorted array and a number n, find if there exists a pair of elements in the array whose difference is n. Examples: Input:… Read More