KU05 AA DivideAndConquer 01
KU05 AA DivideAndConquer 01
Conquer
Introduction
Divide and Conquer
Approach
Divide and Conquer
Engineering Analysing
Divide and
Conquer
Analysis of Algorithms Algorithm
General Equation
Analysing Merge
Sort
Introduction
Divide and Conquer
Approach
Divide and Conquer
Example (Merge
Sort)
1 Introduction Analysing
Divide and
Divide and Conquer Approach Conquer
Algorithm
Divide and Conquer Example (Merge Sort) General Equation
Analysing Merge
Sort
. . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . .
Divide and
Introduction to Divide and Conquer Approach Conquer
Introduction
Divide and Conquer
Approach
Divide and Conquer
Divide Example (Merge
Sort)
Combine
Combine the solutions to the subproblems into a solution
for the original problem (optional).
. . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . .
Divide and
Introduction to Divide and Conquer Approach Conquer
Introduction
Divide and Conquer
Approach
Divide and Conquer
Example (Merge
Sort)
Analysing
Divide and
Conquer
Algorithm
General Equation
Analysing Merge
Sort
. . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . .
Divide and
Merge Sort Conquer
Introduction
Divide and Conquer
Approach
Divide and Conquer
Example (Merge
Sort)
Analysing
Divide and
Conquer
Algorithm
General Equation
Analysing Merge
Sort
. . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . .
Divide and
Merge Sort Conquer
Introduction
Divide and Conquer
Approach
Divide and Conquer
Example (Merge
Sort)
Analysing
Divide and
Conquer
Algorithm
General Equation
Analysing Merge
Sort
. . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . .
Divide and
Merge Sort Conquer
Introduction
Divide and Conquer
Approach
Divide and Conquer
Example (Merge
Sort)
Analysing
Divide and
Conquer
Algorithm
General Equation
Analysing Merge
Sort
. . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . .
Divide and
Analysing Divide and Conquer Algorithm Conquer
Introduction
In general we have the following recurrence equation: Divide and Conquer
Approach
T(n) = Analysing
aT(n/b) + D(n) + C(n) Otherwise. Divide and
Conquer
Algorithm
Where General Equation
Analysing Merge
. . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . .
Divide and
Analysing Merge Sort Algorithm Conquer
Introduction
Divide and Conquer
Approach
Divide and Conquer
Example (Merge
Sort)
Analysing
For merge sort, we have the following recurrence equation: Divide and
Conquer
{ Algorithm
θ(1) if n <= 1, General Equation
T(n) =
2T(n/2) + O(1) + O(n) Otherwise.
Analysing Merge
Sort
. . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . .
Divide and
Solving the recurrence equations Conquer
Introduction
Divide and Conquer
Approach
Divide and Conquer
Example (Merge
Sort)
Analysing
There are different approaches to do this Divide and
Conquer
Algorithm
1 Constructing Recursion Tree General Equation
Analysing Merge
2 Performing Substitution Sort
3 Using Induction
4 Master Theorem
5 Generating Functions
. . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . .
Divide and
Conquer
Introduction
Divide and Conquer
Approach
Divide and Conquer
Example (Merge
Sort)
Analysing
Divide and
Conquer
Algorithm
General Equation
Analysing Merge
Sort
. . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . .
Divide and
Analysing Merge Sort by Performing Conquer
Substitution Introduction
Suppose that n = 2k , for some k ∈ Z. We can write T(n) Divide and Conquer
Approach
Analysing
T(n) = 2T(n/2) + cn Divide and
Conquer
= 2T(2k−1 ) + c2k Algorithm
General Equation
2 k−2 k
= 2 T(2 ) + 2c2
2 k−3
= 2 (2T(2 ) + c2k−2 ) + 2c2k
= 23 T(2k−3 ) + 3c2k
= ...
= 2k T(1) + kc2k
= c‘ n + cn log2 n
= O(n log n)
. . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . .
The End
Questions? Comments?