Module 2: Divide and Conquer: Design and Analysis of Algorithms 18CS42
Module 2: Divide and Conquer: Design and Analysis of Algorithms 18CS42
Module 2: Divide and Conquer: Design and Analysis of Algorithms 18CS42
Algorithms 18CS42
Suriya Prakash J
Dept. of Computer Science and
Engineering
SCE Bangalore
Module 2 –
Outline Divide
and
1. Conquer
General method
2. Recurrence equation
3. Algorithm: Binary search
4. Algorithm: Finding the maximum and
minimum
5. Algorithm: Merge sort
6. Algorithm: Quick sort
7. Algorithm: Strassen’s matrix multiplication
8. Advantages and Disadvantages
9. Decrease and Conquer Approach
10. Algorithm: Topological Sort
18CS42-Design and Analysis of 2
Algorithms
Module 2 –
Outline Divide
and Conquer
1. General method
2. Recurrence equation
3. Algorithm: Binary search
4. Algorithm: Finding the maximum and
minimum
5. Algorithm: Merge sort
6. Algorithm: Quick sort
7. Algorithm: Strassen’s matrix multiplication
8. Advantages and Disadvantages
9. Decrease and Conquer Approach
10. Algorithm: Topological Sort
18CS42-Design and Analysis of 3
Algorithms
Divide and
Conquer
Where,
• T(n) is the time for divide and conquer method on
any input of size n and
• g(n) is the time to compute answer directly for
small inputs.
• The function f(n) is the time for dividing the
problem ‘p’ and combining the solutions to sub
problems.
18CS42-Design and Analysis of Feb-May 7
Algorithms 2020
Recurrence equation for Divide and
Conquer
• Generally, an instance of size n can be divided
into b
instances of size n/b,
• Assuming n = bk ,
18
1 26
2 32
3 6
6 43
4 15
1 9
9 1
1 6
6 1 26
2 32
3 1
1 99 15
1 434
8 6 2 3 5 8 6 2 5 3
118 226 32
3 6
6 443 115 9
9 11 18 26
1 2 6
6 3 15 43
1 4 1
1 99
8 6 2 3 5 8 6 32 2 5 3
18
1 26
2 32
3 6
6 43
4 15
1 99 11 18
1 26
2 32
3 6 43
4 15 9 1
1
8 6 2 3 5 8 6 2 1
3 5 9
1 2 3 6 4 1 9 1
18
8 26
6 32
2 6 43
3 15
5 9 1
L 66 8 8 2 26
32 R 11 9 9 42 42
4
32 ∞ 6 43 ∞ 3
i i i i i j j j j j
dc - 1
Example
We are given array of n integers to sort:
40 20 10 80 60 50
7 30 100
Total comparisons