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

Another Example-Horner's Rule

 

In this section we apply Axioms gif, gif, gif and gif to the analysis of the running time of a program which evaluates the value of a polynomial. That is, given the n+1 coefficients tex2html_wrap_inline57198, and a value x, we wish to compute the following summation

displaymath57194

The usual way to evaluate such polynomials is to use Horner's rule , which is an algorithm to compute the summation without requiring the computation of arbitrary powers of x. The algorithm to compute this summation is given in Program gif. Table gif gives the running times of each of the executable statements in Program gif.

   program416
Program: Program to compute tex2html_wrap_inline57204 using Horner's rule.

 

 

statement time
5 tex2html_wrap_inline57192
6a tex2html_wrap_inline57208
6b tex2html_wrap_inline57172
6c tex2html_wrap_inline57212
7 tex2html_wrap_inline57214
8 tex2html_wrap_inline57178
TOTAL tex2html_wrap_inline57218
tex2html_wrap_inline57220
Table: Computing the running time of Program gif.

Summing the entries in Table gif we get that the running time, T(n), of Program gif is

  equation437

where tex2html_wrap_inline57224 and tex2html_wrap_inline57226.


next up previous contents index

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