# Tagged: Divide and Conquer

## Find the local minima in a given array

Objec­tive:  Given an array of inte­ger write an algo­rithm to find the local min­ima. Local Min­ima: An ele­ment is con­sid­ered as local min­ima if it is less than both of its neigh­bors (if neigh­bors exist). Example:…

## Stock Single Sell Problem — O(n) Solution

Objec­tive:  Given an array rep­re­sents cost of a stock on each day. You are allowed to buy and sell the stock only once. Write an algo­rithm to max­i­mize the profit in sin­gle buy and sell. Example:…

## OR Largest Sum Contiguous Subarray Problem – Divide and Conquer">Maximum Subarray OR Largest Sum Contiguous Subarray Problem – Divide and Conquer

Objec­tive:  The max­i­mum sub­ar­ray prob­lem is the task of find­ing the con­tigu­ous sub­ar­ray within a one-dimensional array of num­bers which has the largest sum. Exam­ple: int [] A = {−2, 1, −3, 4, −1, 2, 1, −5, 4}; Output:…

## Maximum difference between two elements where larger element appears after the smaller element

Objec­tive: Given an array A[], write an algo­rithm to find Max­i­mum dif­fer­ence between two ele­ments where larger ele­ment appears after the smaller ele­ment or in other words find A[i] and A[j] such that A[j]-A[i]…

## Merge Sort — Updated — Most Efficient ways to Implement

Objec­tive : Write Merge Sort algo­rithm to sort ele­ments in an array Input: A unsorted array, arrA[]. Out­put : A sorted array. Approach: Divide and Con­quer: In this approach we divide the main prob­lems into…