You are on page 1of 17

Three Steps of The Divide and

Conquer Approach

The most well known algorithm design strategy:


1. Divide the problem into two or more smaller
subproblems.

2. Conquer the subproblems by solving them


recursively.

3. Combine the solutions to the subproblems


into the solutions for the original problem.
AKRAM_LOQMAN_773133872 3

.1

.2

.3
AKRAM_LOQMAN_773133872 4
Three Steps of The Divide and
Conquer Approach
Problem of size n

Subproblem 1 Subproblem 2
of size n/2 of size n/2

Solution to Solution to
subproblem 1 subproblem 2

Solution to the
AKRAM_LOQMAN_773133872 original probelm 5

1 2
n/2 n/2

AKRAM_LOQMAN_773133872 6
Min And Max Example
Find the min and max of {3,5,6,2,4,9,3,1}.
A = {3,5,6,2} and B = {4,9,3,1}.
min(A) = 2, min(B) = 1.
max(A) = 6, max(B) = 9.
min{min(A),min(B)} = 1.
max{max(A), max(B)} = 9.

AKRAM_LOQMAN_773133872 31

Min and Max


{3,5,6,2,4,9,3,1}

A = {3,5,6,2} and B = {4,9,3,1}.


min(A) = 2, min(B) = 1.
max(A) = 6, max(B) = 9.
min{min(A),min(B)} = 1.
max{max(A), max(B)} = 9.
AKRAM_LOQMAN_773133872 32
Dividing Into Smaller Instances

{8,2,6,3,9,1,7,5,4,2,8}

{8,2,6,3,9} {1,7,5,4,2,8}

{8,2} {6,3,9} {1,7,5} {4,2,8}

{7,5} {4} {2,8}


{6} {3,9} {1}

AKRAM_LOQMAN_773133872 33

Solve Small Instances And Combine

{1,9}

{2,9} {1,8}

{8,2} {3,9} {1,7} {2,8}

{2,8} {6} {3,9} {1} {7,5} {4} {2,8}

{6,6} {3,9} {1,1} {5,7} {4,4} {2,8}

AKRAM_LOQMAN_773133872 34

You might also like