Data Structures and Algorithms with Object-Oriented Design Patterns in C#
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_inline57479, and a value x, we wish to compute the following summation

displaymath57475

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.

   program422
Program: Program to compute tex2html_wrap_inline57485 using Horner's rule.

 

 

statement time
5 tex2html_wrap_inline57473
6a tex2html_wrap_inline57489
6b tex2html_wrap_inline57453
6c tex2html_wrap_inline57493
7 tex2html_wrap_inline57495
8 tex2html_wrap_inline57459
TOTAL tex2html_wrap_inline57499
tex2html_wrap_inline57501
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

  equation443

where tex2html_wrap_inline57505 and tex2html_wrap_inline57507.


next up previous contents index

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