Cover Data Structures and Algorithms with Object-Oriented Design Patterns in Java
next up previous contents index

Running Time of Divide-and-Conquer Algorithms

A number of divide-and-conquer algorithms are presented in the preceding sections. Because these algorithms have a similar form, the recurrences which give the running times of the algorithms are also similar in form. Table gif summarizes the running times of Programs gif, gif and gif.

 

 

program recurrence solution
Program gif T(n)=T(n/2)+O(1) tex2html_wrap_inline58840
Program gif T(n)=2T(n/2)+O(1) O(n)
Program gif T(n)=2T(n/2)+O(n) tex2html_wrap_inline58846
Table: Running times of divide-and-conquer algorithms.

In this section we develop a general recurrence that characterizes the running times of many divide-and-conquer algorithms. Consider the form of a divide-and-conquer algorithm to solve a given problem. Let n be a measure of the size of the problem. Since the divide-and-conquer paradigm is essentially recursive, there must be a base case. That is, there must be some value of n, say tex2html_wrap_inline57984, for which the solution to the problem is computed directly. We assume that the worst-case running time for the base case is bounded by a constant.

To solve an arbitrarily large problem using divide-and-conquer, the problem is divided into a number smaller problems, each of which is solved independently. Let a be the number of smaller problems to be solved ( tex2html_wrap_inline67503, tex2html_wrap_inline67505). The size of each of these problems is some fraction of the original problem, typically either tex2html_wrap_inline67507 or tex2html_wrap_inline67509 ( tex2html_wrap_inline67511, tex2html_wrap_inline67513).

The solution to the original problem is constructed from the solutions to the smaller problems. The running time required to do this depends on the problem to be solved. In this section we consider polynomial running times. That is, tex2html_wrap_inline59848 for some integer tex2html_wrap_inline60398.

For the assumptions stated above, the running time of a divide-and-conquer algorithm is given by

  equation32555

In order to make it easier to find the solution to Equation gif, we drop the tex2html_wrap_inline57116s as well as the tex2html_wrap_inline57438 from the recurrence. We can also assume (without loss of generality) that tex2html_wrap_inline58482. As a result, the recurrence becomes

displaymath67481

Finally, we assume that n is a power of b. That is, tex2html_wrap_inline67529 for some integer tex2html_wrap_inline67531. Consequently, the recurrence formula becomes

  equation32563

We solve Equation gif as follows. Divide both sizes of the recurrence by tex2html_wrap_inline67533 and then telescope :

   eqnarray32573

Adding Equation gif through Equation gif, substituting T(1)=1 and multiplying both sides by tex2html_wrap_inline67533 gives

  equation32604

In order to evaluate the summation in Equation gif we must consider three cases:




next up previous contents index

Bruno Copyright © 1998 by Bruno R. Preiss, P.Eng. All rights reserved.