Data Structures and Algorithms with Object-Oriented Design Patterns in Python
next up previous 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_inline57703, and a value x, we wish to compute the following summation

displaymath57699

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.

   program413
Program: Program to compute tex2html_wrap_inline57709 using Horner's rule.

 

 

statement time
2 tex2html_wrap_inline57697
3 tex2html_wrap_inline57713
4 tex2html_wrap_inline57677
5 tex2html_wrap_inline57717
6 tex2html_wrap_inline57719
7 tex2html_wrap_inline57683
TOTAL tex2html_wrap_inline57723
tex2html_wrap_inline57725
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

  equation433

where tex2html_wrap_inline57729 and tex2html_wrap_inline57731.


next up previous index

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