Logo 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_inline57278, and a value x, we wish to compute the following summation

displaymath57274

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_inline57284 using Horner's rule.

 

 

statement time
5 tex2html_wrap_inline57272
6a tex2html_wrap_inline57288
6b tex2html_wrap_inline57252
6c tex2html_wrap_inline57292
7 tex2html_wrap_inline57294
8 tex2html_wrap_inline57258
TOTAL tex2html_wrap_inline57298
tex2html_wrap_inline57300
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_inline57304 and tex2html_wrap_inline57306.


next up previous contents index

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