Professional Documents
Culture Documents
Divide-and-Conquer
Divide-and-Conquer
A. Levitin “Introduction to the Design & Analysis of Algorithms,” 3rd ed., Ch. 4 4-2
Divide-and-Conquer Technique (cont.)
a problem of size n
(instance)
subproblem 1 subproblem 2
of size n/2 of size n/2
a solution to a solution to
subproblem 1 subproblem 2
A. Levitin “Introduction to the Design & Analysis of Algorithms,” 3rd ed., Ch. 4 4-4
General Divide-and-Conquer Recurrence
A. Levitin “Introduction to the Design & Analysis of Algorithms,” 3rd ed., Ch. 4 4-5
Binary Search
Binary search is a remarkably efficient algorithm for
searching in a sorted array.
A. Levitin “Introduction to the Design & Analysis of Algorithms,” 3rd ed., Ch. 4 4-6
Binary Search
A. Levitin “Introduction to the Design & Analysis of Algorithms,” 3rd ed., Ch. 4 4-7
Binary Search
Number of key comparisons in The worst-case inputs include
all arrays that do not contain a given search key.
A. Levitin “Introduction to the Design & Analysis of Algorithms,” 3rd ed., Ch. 4 4-8
Analysis of Binary Search
A. Levitin “Introduction to the Design & Analysis of Algorithms,” 3rd ed., Ch. 4 4-9
Binary Tree Algorithms
A. Levitin “Introduction to the Design & Analysis of Algorithms,” 3rd ed., Ch. 4 4-10
Binary Tree Algorithms (cont.)
TL TR
A. Levitin “Introduction to the Design & Analysis of Algorithms,” 3rd ed., Ch. 4 4-11
Multiplication of Large Integers
Consider the problem of multiplying two (large) n-digit integers
represented by arrays of their digits such as:
A = 12345678901357986429 B = 87654321284820912836
2135 4014
A. Levitin “Introduction to the Design & Analysis of Algorithms,” 3rd ed., Ch. 4 4-16
Closest Pair by Divide-and-Conquer (cont.)
Step 2 Find recursively the closest pairs for the left and right
subsets.
A. Levitin “Introduction to the Design & Analysis of Algorithms,” 3rd ed., Ch. 4 4-18
Closest Pair by Divide-and-Conquer: Algorithm
A. Levitin “Introduction to the Design & Analysis of Algorithms,” 3rd ed., Ch. 4 4-19
Efficiency of the Closest-Pair Algorithm
A. Levitin “Introduction to the Design & Analysis of Algorithms,” 3rd ed., Ch. 4 4-20