You are on page 1of 3

# Contents

## Divde and Conquer

1.1

Steps

1. Divide the problem into smaller problems that are instances of the
same type
2. Conquer the sub problem by solving them recursively. But, if the
sub problems are small enough, just solve them in a straight forward
manner
3. Combine the solutions to the subproblems into the solution for the
original problem.
Generally, a recursive algorithm works by calling itself on smaller instances of the problem.
1. The algorithm is generally made of the 3 steps described above.
2. It receives a set of input
3. It divides the set of input into 2 and calls itself on those 2
4. Each of the subproblems in 3) is again solved from step 2)
Any subproblem that is divisible by the algorithm into subproblems is
called a recursive case.
Any subproblem that is simple enough or not divisble into a smaller
problem is called a base case, and base cases are solved in a straight
forward way
5. The algorithm then combines the solved base cases into solutions and
groups them by their subproblem units. Lets now call them sub solutions. Since the original subproblems were children of a large subproblem, the solutions will belong to parent groups. The assemblage
continues until 2 solution units are obtained. The last 2 solution units
are combined to form a single solution to the original problem.
Another way of looking at the divide and conquer paradigm is as such:
For sorting

## 1. Divide the problems until you have individual elements

2. At this very basic fundamental stage, every single element is solved or
sorted
3. Now group them into groups of two(s) from left to right.
If there are n single elements, and we have groups of two(s), there
we shall have n/2 groups, each with size 2.
Now group the n/2 groups into groups of two(s) again, resulting
into n/4 groups, but make sure that each resulting group is solved.
Continue grouping till you have a situation where n/b = 2. In
this situation we have just 2 groups of solutions which we then
merge to form the result
4. Once we have suciently grouped the subunits to get a single unit of
the solution, we return.

1.2

Recurrences

## A recurrence is an equation or inequality that describes a function in terms

of its value on smaller inputs.
Recurrences often take a problem with input n and divide it into 2 units:
1. a sub problem of size 1
2. a subproblem of size n-1
Note that (n-1)+1 = n, the original size of the problem
So the recurrence gotten would be:
T(n) = T(n-1) + (1)

1.3

## 1. Subsitution method: Guess bound and use math induction to prove

guess
2. Recursion-tree method: Convert recursion into tree whose nodes represent each cost incurred at every level, depicted by the tree.
3. Master method: Used for problems of the form: T(n) = aT(n/b) +
f(n) That is a problem of size n divided into a subproblems each of size
n/b
2

1.4

Notes on Recurrences

## Sometimes, a problem may have size, n such that n = 2m+1, that is n is

odd. Dividing this subproblem into 2 groups leaves on group with size odd.
So taking this into perspective, we actually need floors and Ceilings in
solving recurrences.
So a true recurrence equation is like below:
{
(1)
if n = 1
T(n) =
T (n/2) + T (n/2) + (n)
if n > 1