Documente Academic
Documente Profesional
Documente Cultură
Jon Louis B e n t l e y 2
D o r o t h e a Haken
James B. Saxe
D e p a r t m e n t of Computer Science
Carnegie-Mellon University
P i t t s b u r g h , Pennsylvania 1 5 2 1 3
Abstract
1. Introduction
1This research was suppolted in part by the Office of Naval Researchunder Contract N00014-76-C-0370.
h a v e t h e form 3
T ( 1 ) given,
T ( n ) = k T ( n / c ) + f(n).
M u c h w o r k has b e e n done on s y s t e m a t i c w a y s of solving r e c u r r e n c e s of this form;
s e e , f o r e x a m p l e , Aho, Hopcroft and Ullman [ 1 9 7 4 , pp. 6 4 - 6 5 J , Borodin and M u n r o
[ 1 9 7 5 , p. 8 0 ] , Keller [ 1 9 8 0 ] , and Stanat and McAIlister [ 1 9 7 7 , pp. 2 4 9 , 2 5 5 ] . The
o n l y w e l l - d e f i n e d methods d e s c r i b e d by the above authors, h o w e v e r , c o n s i s t of
s o l u t i o n t a b l e s for f i x e d functions f and varying k and c. Although this m e t h o d Is
q u i t e s a t i s f a c t o r y w h e n appliecl to r e c u r r e n c e s with common f, t h e r e are many t i m e s
w h e n a f u n c t i o n f a r i s e s t h a t has not been previously t a b u l a t e d .
2, A Simple Example
3 N o t e that T(n) is defined only when n is a power of c; the implications of this restrictioP, are discussed by Aho,
Hopcroft and UIIman [ 1974, p. 65].
SIGACT News 38 Fall 1980
T ( n ) = ~ i~<q n] + n'T(l)
__ gn
1 + T(1 )]
=n[l_._g n
= n[Ign+ 1],
3. The Template
= g(21).
1 _<i_<lg n
The above facts I)rovide us with a method for solving any r e c u r r e n c e in t h e form
o f E q u a t i o n 1. We c a s t it in the template of Equation 2 by dividing and t a k i n g a
l o g a r i t h m ; and then the solution to the r e c u r r e n c e is given by Equation 8. The £ n l y
c o m p l i c a t e d p a r t of this p r o c e s s is determining the sum implicit in the f u n c t i o n g tn
4Throughout this paper w e use Ig n as an abbreviation for log 2 n and Ig j n as an abbreviation for (Ig n) j.
SIGACT News 39 Fall 1980
E q u a t i o n 8, av2(l this can usually be done with the aid of the following t a b l e In w h i c h
we describe g in relation to g,
Table 1
4. Examples
Example 1. T(n) = r ( n / 2 ) + 1
E x a m p l e 2, T(n) = 2 T ( n / 2 ) + n Ig n
Example 4. T(n) = T ( n / 2 ) + n Ig n
5 . A M o r e General Template
T ( n ) = c P T ( n / c ) + nPg(n),
w h e r e p = log c k and g(n) = f(n)/nP. The solution to this modified r e c u r r e n c e Is
T(n) = n P [ T ( 1 ) + ~ g(ci)].
l_<i_<log c n
As in S e c t i o n 8, the proof that this is the unique solution to the r e c u r r e n c e is by
m a t h e m a t i c a l induction on the i;owers of c. For monotone functions g it can be
p r o v e d t h a t the above sum differs from ~(n) by at most a f a c t o r of Ig c, so Table 1
c a n be used to solve the recurrence to within a constant factor.
This t e m p l a t e can be used, for example, to analyze the running time of Panes
[1 9 7 8 ] m a t r i x multiplication algorithm, which satisfies the r e c u r r e n c e
6. Extensions
T ( n ) = n • (2 Ig n - 1).
( T h e r e a d e r is encourage(t to r e p e a t this exercise with "tg n" replaced by "lg Ig n"
in t h e s t a t e m e n t of the recurrence,)
N o t e t h a t the sum of the values of all nodes in the tree gives 32, which Is e x a c t l y
T ( 8 ) . In general, the recursion tree for the evaluation of Recurrence 4 at the v a l u e
n Is
- a single node with the value T(no), if n=no;
- o t h e r w i s e , a node with the value f(n) and a(n) sons, each of whtch Is a
r e c u r s i o n t r e e for the evaluation of the recurrence at b(n).
N o t e t h a t t h e sum of the values of all nodes in the tree gives precisely T(n).
d e f i n e t w o o f their properties. The first ts the depth of the recursion tree, which w e
w r i t e as RD(n), for recurslon depth (the depth of the above tree ts t h r e e ) . The
s e c o n d Is the number of leaves tn tile recurslon tree, wl~lch is defined by the
recurrence
L(n o) = 1,
L(n) = a(n)I_(b(n)).
(Notice t h a t l.(n) is just one of the homogeneous soltHions of Recurrence 4.) We
can now describe the value of 7(I1) by a case analysis of f(n)/L(n), wllich is the
r a t i o of the work at the root to the number of leaves in the tree.
If f ( n ) l l ( n ) = O(q "RD(n)) for some q>O, then T(n) = #(L(n)), (That is,
the work at the leave.'; dominates the cost.)
= If f(n)/L(n) = O(f~lD(n)J) for some nonnegative J, then
T(n) = O(f(n)'RD(n)). (That is, the work is approximalely equal at all
RD(n) levels of the tree.)
- If f ( n ) / L ( n ) = ~(qFID(n)) for some q>O, then T(n) = O(f(n)). (That Is, the
w o r k at the root dominates the cost.)
Notlc,e t h a t the above case analysis is isomorphic to Table 1 when a(n) Is k and b(n)
Is n / 2 ; as In that table, not all possible cases of f(n)/L(n) are enumerated above.
7. Conclusions
To conclude this paper we will briefly review its contents. The primary
c o n t r i b u t i o n Is the method that we presented to solve the various r e c u r r e n c e s - -
r e w r i t i n g the recurrence hy ctecomposing the additive term Into some function times
a solution of the homogeneous system. We described this method both in the v e r y
general terms of a recursion tree, and in the specific framework of
d i v i d e - a n d - c o n q u e r recurrences. This method can he applied hy memorizing a simple
t e m p l a t e (or the recursion tree formulation) and a table of three entries. While the
novice can use this framework to solve (approximately) d i v i d e - a n d - c o n q u e r
r e c u r r e n c e s , the more experienced algorithm designer Call rise It In a more
a d v a n c e d fashion: to prune his search for an efficient alaorithm. For. examale, If he
w e r e t r y i n g to find an O(n 103 n) algorithm I)y marrying tc~gether the solutlc~n to t w o
problems of size n/2 each, his marriage step must require O(n lg 2 n) time.
Much w o r k remains to he done ill developing general methods for rapidly solving
e q u a t i o n s t h a t descrlhe the al)proximate complexity of algorithms; we mentioned
some areas for further work In Section 6. Such methods will never be s u f f i c i e n t for
the detatled "Kntlthian" analysis of algorithms, but they can free algorithm designers
from mundane analyses to let them work on more interesting problems.
Acknowledgements
The authors would like to thank Professor D.E, Knuth for (properly) chiding us
a b o u t the '"cook book" flavor of all earlier draft, and Professor V, Pratt for
s u g g e s t i n g the recursion tree formulation of Section 6.
SIGACT News 44 Fall 1980
References
Aho, A.V., J.E. ttopcroft and J.D. UIIman [1974]. The Design and Analysis of
Computer Algorithms, Addison-Wesley, Reading, Mass.
Bentley, J.L. and M.I. Shames [1976]. "Divide and conquer In multidimensional
space", Proceedings of the Eighth Symposium on the Theory of Computing,
ACM, May 1976, pp. 220-230.
Borodin, A. and I. Munro [ 1 9 7 5 ] . The Computational Complexity of Algebraic and
Numeric Problems, American Elsevier, New York, N.Y.
Ford, L. and S. Johnson [1959]. "A tournament problem", American Mathematical
Monthly 66, pp. 391-305.
Keller, K . [ 1 9 8 0 ] . "Computation cost f,nctions for divide-and-conquer algorithms",
to appear In Journal of Undergraduate Mathematics.
Knuth, D.E. [ 1 9 7 3 ] . The ~qrt of Computer Programming, volume 3: Sorting and
Searching, Addison-Wesley, Reading, Mass.
Kung, H. T. [1 973]. A New Upper Bound on the Complexity of Derivative Evaluation,
Carnegie-Mellon University Computer Science Report, September 1978.
Kung, H. T., F. Luccio and F. P. Preparata [1975]. "On finding the maxima of a set of
vectors", JACM 22, 4, October 1975, pp. 469-476.
Ltu, C. L. [ 1 9 7 7 ] . Elements of Discrete Mathematics, McGraw-Hill, New York, N. Y.
Manacher, G.K. [1977.]. "The Ford-Johnson sorting algorithm is not optimal",
Proceedings of the Fifteenth Annual Allerton Conference on Communications,
Control and Computing, Sepember 1977, pp. 390-397.
Pan, V. Ya. [1 978,]. ,An introduction to the trilinear technique of agoregating, uniting
and canceling and applications of the technique for constructing fast
algorithms for matrix operations", Proceedings of the Nineteenth Annual
Symposium on the Foundations of Computer Science, IEEE, 1978.
Stanat, D.F. and D.F. McAIlister [1¢177]. Discrete Mathematics in Computer
Science, Prentice-Hall, Englewood Cliffs, N. J.
Strassen, V. [ 1 9 6 9 ] . "Gaussian elimination is not optimal", Numerische Mathematik
18, pp. ,354-356.