Many recursive algorithms take a problem with a given input and divide it
into one or more smaller problems. This reduction is repeatedly applied until
the solutions of smaller problems can be found quickly. This procedure is
called divide-and-conquer algorithm. These algorithms divide a problem
into one or more instances of the same problem of smaller size and they
conquer the problem by using the solutions of the smaller problems to find a
solution of the original problem, possibly with some additional work.
Suppose that a rec. algorithm divides a problem of size n into a parts, where
each sub-problem is of size n/b. Also suppose that a total number of g(n)
extra operations are needed in the conquer step of the algorithm to combine
the solutions of the sub-problems into a solution of the original problem. Let
f(n) be the number of operations required to solve the problem of size n.
Then f satisfies the recurrence relation
f(n)=a f(n/b)+g(n)
and it is called divide-and-conquer recurrence relation.
1
Math 2320 B, Lecture 04, Last printed 10/1/2007 10:43 PM
to compare the min of the two sub-lists. So the rec. rel. is f(n)=2 f(n/2)+2
for even n.
This means that the multiplication of two 2n-bit integers can be carried out
using multiplication of three n-bit integers plus some shifts, subtractions and
additions. So if f(n) is the total number of bit operations needed to multiply
two n-bit integers, then f(2n)=3f(n)+Cn, where Cn is number of shifts,
subtractions and additions which is needed to carry out multiplication of
three n-bit integers: 3f(n).
f(n)=a f(n/b)+g(n)
.
.
2
Math 2320 B, Lecture 04, Last printed 10/1/2007 10:43 PM
Since , we have
.
Applying this equation for f(n) can be used to estimate the size of functions
which satisfy the divide-and-conquer recursive relations.
Theorem 1
3
Math 2320 B, Lecture 04, Last printed 10/1/2007 10:43 PM
Example 8 Estimate the number of comparisons needed to find the max and
the min elements of the list with n elements.
4
Math 2320 B, Lecture 04, Last printed 10/1/2007 10:43 PM