Tag Archives: Binary-Search

Binary Search functions in C++ STL (binary_search, lower_bound and upper_bound)

Binary search is an important component in competitive programming or any algorithmic competition, having knowledge of shorthand functions reduces the time to code them. This searching only works when container is sorted. Related functions are discussed below. 1.binary_search(start_ptr, end_ptr, num) : This function returns boolean true if the element is present in the container, else… Read More »

Search, insert and delete in a sorted array

In this post search, insert and delete operation in a sorted array is discussed. Search Operation In a sorted array, the search operation can be performed by using binary search. Output: Index: 5 Insert Operation In an unsorted array, the insert operation is faster as compared to sorted array because we don’t have to care… Read More »

Allocate minimum number of pages

Given number of pages in n different books and m students. The books are arranged in ascending order of number of pages. Every student is assigned to read some consecutive books. The task is to assign books in such a way that the maximum number of pages assigned to a student is minimum. Input :… Read More »

Find the missing number in Geometric Progression

Given an array that represents elements of geometric progression in order. One element is missing in the progression, find the missing number. It may be assumed that one term is always missing and the missing term is not first or last of series. Examples: Input : arr[] = {1, 3 , 27, 81} Output :… Read More »

Exponential Search

The name of this searching algorithm may be misleading as it works in O(Log n) time. The name comes from the way it searches an element. Given a sorted array an element x to be searched, find position of x in the array. Input: arr[] = {10, 20, 40, 45, 55} x = 45 Output:… Read More »

Find a local minima in an array

Given an array arr[0 .. n-1] of distinct integers, the task is to find a local minima in it. We say that an element arr[x] is a local minimum if it is less than or equal to both its neighbors. For corner elements, we need to consider only one neighbor for comparison. There can be… Read More »