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

Example-Geometric Series Summation Yet Again

In this example we consider the problem of computing a geometric series summation  for the last time. We have already seen two algorithms to compute this summation in Sections gif and gif (Programs gif and gif).

An algorithm to compute a geometric series summation using the closed-form expression (Equation gif) is given in Program gif. This algorithm makes use of Program gif to compute tex2html_wrap_inline58109.

   program1162
Program: Program to compute tex2html_wrap_inline57855 using the closed-form expression.

To determine the average running time of Program gif we will make use of Equation gif, which gives the average running time for the Power method which is called on line 5. In this case, the arguments are x and n+1, so the running time of the call to Power is tex2html_wrap_inline58117. Adding to this the additional work done on line 5 gives the average running time for Program gif:

displaymath58107

The running times of the three programs which compute the geometric series summation presented in this chapter are tabulated below in Table gif and are plotted for tex2html_wrap_inline58119 in Figure gif. The plot shows that, according to our simplified model of the computer, Program gif has the best running time for n<4. However as n increases, Program gif is clearly the fastest of the three and Program gif is the slowest for all values of n.

 

 

program T(n)
Program gif tex2html_wrap_inline58127
Program gif 13n+22
Program gif tex2html_wrap_inline58131
Table: Running times of Programs gif, gif and gif.

   figure1199
Figure: Plot of running time vs. n for Programs gif, gif and gif.


next up previous contents index

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