KU05 AA DivideAndConquer 02
KU05 AA DivideAndConquer 02
Conquer
Analysing
Divide and
Conquer
Algorithm
Computer Science Faculty - Software General Equation
Master Theorem
Divide and
Conquer
Analysis of Algorithms‘ Course Lectures Algorithm
(without
( Divide and Conquer ) Combination)
Binary Search
Analysing
Divide and
Conquer
Algorithm
1 Analysing Divide and Conquer Algorithm General Equation
Master Theorem
General Equation
Quick Sort
Master Theorem Algorithm
Introduction
Analysing Quick
Sort
. . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . .
Divide and
Analysing Divide and Conquer Algorithm Conquer
Analysing
In general we have the following recurrence equation: Divide and
Conquer
{ Algorithm
. . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . .
Divide and
Solving the recurrence equations Conquer
Analysing
Divide and
Conquer
Algorithm
General Equation
Master Theorem
5 Generating Functions
. . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . .
Master Thearem
Analysing
Divide and
Conquer
Algorithm
General Equation
Master Theorem
. . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . .
Divide and
QuickSort Conquer
Analysing
Divide Divide and
Conquer
for sorting A[p..r], Partition A[p..r], into two subarrays Algorithm
General Equation
A[p..q1] and A[q + 1..r], such that each element in the Master Theorem
first subarray A[p..q1] is <= A[q] and A[q] is <= each Quick Sort
Algorithm
element in the second subarray A[q + 1..r]. Introduction
Analysing Quick
Sort
. . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . .
Divide and
QuickSort Algorithm Conquer
Analysing
Divide and
Conquer
Algorithm
General Equation
Master Theorem
Quick Sort
Algorithm
Introduction
Analysing Quick
Sort
Divide and
Conquer
Algorithm
(without
Combination)
Binary Search
. . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . .
Divide and
QuickSort Algorithm Conquer
Analysing
Divide and
Conquer
Algorithm
General Equation
Master Theorem
Quick Sort
Algorithm
Introduction
Analysing Quick
Sort
Divide and
Conquer
Algorithm
(without
Combination)
Binary Search
. . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . .
Divide and
QuickSort Algorithm Conquer
Analysing
Divide and
Conquer
Algorithm
General Equation
Master Theorem
Quick Sort
Trace QuickSort with these samples: Algorithm
Introduction
First Example: Analysing Quick
Sort
A = [15, 22, 13, 27, 12, 10, 20, 25] Divide and
Second Example: Conquer
Algorithm
A = [2, 8, 7, 1, 3, 5, 6, 4] (without
Combination)
Trace overall work procedure and partition procedure Binary Search
. . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . .
Divide and
Conquer
Analysing
Divide and
Conquer
Algorithm
General Equation
Master Theorem
Quick Sort
Algorithm
Introduction
Analysing Quick
Sort
Divide and
Conquer
Algorithm
(without
Combination)
Binary Search
. . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . .
Divide and
Analysing Quick Sort Algorithm Conquer
Quick Sort
= T(n − 1) + Θ(n) Algorithm
Introduction
Analysing Quick
Sort
k=1
= Θ(n2 )
So
T(n) = θ(n2 )
. . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . .
Divide and
Analysing Quick Sort Algorithm Conquer
Analysing
Divide and
Conquer
Algorithm
Best Case General Equation
Master Theorem
Divide and
Conquer
T(n) = 2T(n/2) + θ(n) Algorithm
(without
Combination)
Binary Search
So
. . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . .
Divide and
Analysing Quick Sort Algorithm Conquer
Analysing
Divide and
Conquer
Average Case Algorithm
General Equation
Quick Sort
the best case than to the worst case. Algorithm
Introduction
So
. . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . .
Analysing Quick Sort Algorithm - Average
Case
Analysing
Divide and
Conquer
An example of Divide and Conquer with not Containing Algorithm
Combination General Equation
Master Theorem
Divide and
Conquer
Algorithm
(without
Combination)
Binary Search
. . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . .
Divide and
Binary Search Conquer
Analysing
Divide and
Conquer
Algorithm
Divide and Conquer Approach without Combination Step General Equation
Master Theorem
Quick Sort
Binary-Search(x,k){ Algorithm
6. return Binary-Search(x.right, k)
7. }
. . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . .
The End
Questions? Comments?