Unit2 1DivideNConquerRecurrence
Unit2 1DivideNConquerRecurrence
SE 208
Unit 2-1
Searching and Sorting (Divide and Conquer)
Divyashikha Sethia
[email protected]
DTU
Divide and Conquer Algorithms
• Basic Idea
• Binary Search
• Merge Sort
• Quick Sort
• Stassen Multiplication
• Heap Sort
• Analysis Divide and Conquer run time recurrence
relation
• Conclusion
2
Basic Idea
◼Divide instance of problem into two or more smaller instances
3
Basic Idea
a problem of size n
subproblem 1 subproblem 2
of size n/2 of size n/2
a solution to a solution to
subproblem 1 subproblem 2
a solution to
the original problem
4
General Divide-and-Conquer Recurrence
5
Examples
7
Analysis of Binary Search
8
9
10
Mergesort
11
Mergesort
12
Mergesort
13
Mergesort
8 3 2 9 7 1 5 4
8 3 2 9 7 1 5 4
8 3 2 9 7 1 5 4
8 3 2 9 7 1 5 4
3 8 2 9 1 7 4 5
2 3 8 9 1 4 5 7
1 2 3 4 5 7 8 9
14
Mergesort Code
• T(N) = 2T(N/2) + N
18
Features of Mergesort
19
• Referenecs
• Cormen Chapter 4
20