Category Archives: Divide and Conquer

QuickSortJanuary 7, 2014

Like Merge Sort, QuickSort is a Divide and Conquer algorithm. It picks an element as pivot and partitions the given array around the picked pivot.

Closest Pair of Points | O(nlogn) ImplementationNovember 28, 2013

We are given an array of n points in the plane, and the problem is to find out the closest pair of points in the… Read More »

Find the minimum element in a sorted and rotated arrayJuly 2, 2013

A sorted array is rotated at some unknown point, find the minimum element in it. Following solution assumes that all elements are distinct.

Unbounded Binary Search Example (Find the point where a monotonically increasing function becomes positive first time)June 19, 2013

Given a function ‘int f(unsigned int x)’ which takes a non-negative integer ‘x’ as input and returns an integer as output.

Find a peak elementMay 18, 2013

Given an array of integers. Find a peak element in it. An array element is peak if it is NOT smaller than its neighbors. For… Read More »

Divide and Conquer | Set 4 (Karatsuba algorithm for fast multiplication)April 18, 2013

Given two binary strings that represent value of two integers, find the product of two strings. For example, if the first bit string is “1100”… Read More »

Largest Rectangular Area in a Histogram | Set 1April 8, 2013

Find the largest rectangular area possible in a given histogram where the largest rectangle can be made of a number of contiguous bars. For simplicity,… Read More »

Divide and Conquer | Set 3 (Maximum Subarray Sum)March 16, 2013

You are given a one dimensional array that may contain both positive and negative integers, find the sum of contiguous subarray of numbers which has… Read More »

Merge SortMarch 15, 2013

Like QuickSort, Merge Sort is a Divide and Conquer algorithm. It divides input array in two halves, calls itself for the two halves and then… Read More »

Divide and Conquer | Set 2 (Closest Pair of Points)November 28, 2012

We are given an array of n points in the plane, and the problem is to find out the closest pair of points in the… Read More »

Divide and Conquer | Set 1 (Introduction)November 15, 2012

Like Greedy and Dynamic Programming, Divide and Conquer is an algorithmic paradigm. A typical Divide and Conquer algorithm solves a problem using following three steps.

Median of two sorted arrays of different sizesSeptember 28, 2012

This is an extension of median of two sorted arrays of equal size problem. Here we handle arrays of unequal size also.

Find the maximum element in an array which is first increasing and then decreasingJanuary 14, 2012

Given an array of integers which is initially increasing and then decreasing, find the maximum value in the array.

Find a Fixed Point (Value equal to index) in a given arrayDecember 1, 2011

Given an array of n distinct integers sorted in ascending order, write a function that returns a Fixed Point in the array, if there is… Read More »

Count number of occurrences (or frequency) in a sorted arrayMay 3, 2011

Given a sorted array arr[] and a number x, write a function that counts the occurrences of x in arr[]. Expected time complexity is O(Logn)