page50.html
来自「Data Structures And Algorithms With Obje」· HTML 代码 · 共 85 行
HTML
85 行
<HTML><HEAD><TITLE>An example-Geometric Series Summation</TITLE></HEAD><BODY bgcolor="#FFFFFF"> <a href="../index.html" target="_top"><img src="../icons/usins.gif" alt="Logo" align=right></a><b>Data Structures and Algorithms with Object-Oriented Design Patterns in Python</b><br><A NAME="tex2html1783" HREF="page51.html"><IMG WIDTH=37 HEIGHT=24 ALIGN=BOTTOM ALT="next" SRC="../icons/next_motif.gif"></A> <A NAME="tex2html1781" HREF="page49.html"><IMG WIDTH=26 HEIGHT=24 ALIGN=BOTTOM ALT="up" SRC="../icons/up_motif.gif"></A> <A NAME="tex2html1775" HREF="page49.html"><IMG WIDTH=63 HEIGHT=24 ALIGN=BOTTOM ALT="previous" SRC="../icons/previous_motif.gif"></A> <A NAME="tex2html1785" HREF="page611.html"><IMG WIDTH=43 HEIGHT=24 ALIGN=BOTTOM ALT="index" SRC="../icons/index_motif.gif"></A> <BR><HR><H2><A NAME="SECTION002210000000000000000">An example-Geometric Series Summation</A></H2><A NAME="secmodelgeometric"> </A><P>In this section we consider the running timeof a program to compute the following<em>geometric series summation</em><A NAME=868> </A>.That is, given a value <I>x</I> and non-negative integer <I>n</I>,we wish to compute the summation<P> <IMG WIDTH=271 HEIGHT=44 ALIGN=BOTTOM ALT="displaymath58075" SRC="img132.gif" ><P>An algorithm to compute this summationis given in Program <A HREF="page50.html#progexamplef"><IMG ALIGN=BOTTOM ALT="gif" SRC="../icons/cross_ref_motif.gif"></A>.<P><P><A NAME="1208"> </A><A NAME="progexamplef"> </A> <IMG WIDTH=575 HEIGHT=237 ALIGN=BOTTOM ALT="program872" SRC="img134.gif" ><BR><STRONG>Program:</STRONG> Program to compute <IMG WIDTH=53 HEIGHT=27 ALIGN=MIDDLE ALT="tex2html_wrap_inline58081" SRC="img133.gif" >.<BR><P><P>Table <A HREF="page50.html#tblgeometricc"><IMG ALIGN=BOTTOM ALT="gif" SRC="../icons/cross_ref_motif.gif"></A> gives the running time,as predicted by the simplified model,for each of the executable statements in Program <A HREF="page50.html#progexamplef"><IMG ALIGN=BOTTOM ALT="gif" SRC="../icons/cross_ref_motif.gif"></A>.<P><P><A NAME="1210"> </A><P> <A NAME="tblgeometricc"> </A> <DIV ALIGN=CENTER><P ALIGN=CENTER><TABLE COLS=2 BORDER FRAME=HSIDES RULES=GROUPS><COL ALIGN=CENTER><COL ALIGN=CENTER><TBODY><TR><TD VALIGN=BASELINE ALIGN=CENTER NOWRAP> statement </TD><TD VALIGN=BASELINE ALIGN=CENTER NOWRAP> time </TD></TR></TBODY><TBODY><TR><TD VALIGN=BASELINE ALIGN=CENTER NOWRAP>2 </TD><TD VALIGN=BASELINE ALIGN=CENTER NOWRAP> 2 </TD></TR><TR><TD VALIGN=BASELINE ALIGN=CENTER NOWRAP> 3 </TD><TD VALIGN=BASELINE ALIGN=CENTER NOWRAP> 2 </TD></TR><TR><TD VALIGN=BASELINE ALIGN=CENTER NOWRAP> 4 </TD><TD VALIGN=BASELINE ALIGN=CENTER NOWRAP> 3(<I>n</I>+2) </TD></TR><TR><TD VALIGN=BASELINE ALIGN=CENTER NOWRAP> 5 </TD><TD VALIGN=BASELINE ALIGN=CENTER NOWRAP> 2(<I>n</I>+1) </TD></TR><TR><TD VALIGN=BASELINE ALIGN=CENTER NOWRAP> 6 </TD><TD VALIGN=BASELINE ALIGN=CENTER NOWRAP> 2(<I>n</I>+1) </TD></TR><TR><TD VALIGN=BASELINE ALIGN=CENTER NOWRAP> 7 </TD><TD VALIGN=BASELINE ALIGN=CENTER NOWRAP> <IMG WIDTH=92 HEIGHT=25 ALIGN=MIDDLE ALT="tex2html_wrap_inline58093" SRC="img135.gif" > </TD></TR><TR><TD VALIGN=BASELINE ALIGN=CENTER NOWRAP> 8 </TD><TD VALIGN=BASELINE ALIGN=CENTER NOWRAP> <IMG WIDTH=57 HEIGHT=25 ALIGN=MIDDLE ALT="tex2html_wrap_inline58095" SRC="img136.gif" > </TD></TR><TR><TD VALIGN=BASELINE ALIGN=CENTER NOWRAP> 9 </TD><TD VALIGN=BASELINE ALIGN=CENTER NOWRAP> <IMG WIDTH=57 HEIGHT=25 ALIGN=MIDDLE ALT="tex2html_wrap_inline58095" SRC="img136.gif" > </TD></TR><TR><TD VALIGN=BASELINE ALIGN=CENTER NOWRAP> 10 </TD><TD VALIGN=BASELINE ALIGN=CENTER NOWRAP> 4(<I>n</I>+1) </TD></TR><TR><TD VALIGN=BASELINE ALIGN=CENTER NOWRAP> 11 </TD><TD VALIGN=BASELINE ALIGN=CENTER NOWRAP> 4(<I>n</I>+1) </TD></TR><TR><TD VALIGN=BASELINE ALIGN=CENTER NOWRAP> 12 </TD><TD VALIGN=BASELINE ALIGN=CENTER NOWRAP> 2 </TD></TR></TBODY><TBODY><TR><TD VALIGN=BASELINE ALIGN=CENTER NOWRAP>TOTAL </TD><TD VALIGN=BASELINE ALIGN=CENTER NOWRAP> <IMG WIDTH=113 HEIGHT=29 ALIGN=MIDDLE ALT="tex2html_wrap_inline58105" SRC="img137.gif" > </TD></TR></TBODY><CAPTION ALIGN=BOTTOM><STRONG>Table:</STRONG> Computing the running time of Program <A HREF="page50.html#progexamplef"><IMG ALIGN=BOTTOM ALT="gif" SRC="../icons/cross_ref_motif.gif"></A>.</CAPTION></TABLE></P></DIV><P><P>In order to calculate the total cycle counts,we need to evaluate the two series summations <IMG WIDTH=81 HEIGHT=25 ALIGN=MIDDLE ALT="tex2html_wrap_inline58107" SRC="img138.gif" > and <IMG WIDTH=45 HEIGHT=25 ALIGN=MIDDLE ALT="tex2html_wrap_inline58109" SRC="img139.gif" >.Both of these are<em>arithmetic series summations</em><A NAME=906> </A>.In the next section we showthat the sum of the series <IMG WIDTH=66 HEIGHT=22 ALIGN=MIDDLE ALT="tex2html_wrap_inline58111" SRC="img140.gif" > is <I>n</I>(<I>n</I>+1)/2.Using this result we can sum the cycle countsgiven in Table <A HREF="page50.html#tblgeometricc"><IMG ALIGN=BOTTOM ALT="gif" SRC="../icons/cross_ref_motif.gif"></A>to arrive at the total running time of <IMG WIDTH=113 HEIGHT=29 ALIGN=MIDDLE ALT="tex2html_wrap_inline58105" SRC="img137.gif" > cycles.<P><HR><A NAME="tex2html1783" HREF="page51.html"><IMG WIDTH=37 HEIGHT=24 ALIGN=BOTTOM ALT="next" SRC="../icons/next_motif.gif"></A> <A NAME="tex2html1781" HREF="page49.html"><IMG WIDTH=26 HEIGHT=24 ALIGN=BOTTOM ALT="up" SRC="../icons/up_motif.gif"></A> <A NAME="tex2html1775" HREF="page49.html"><IMG WIDTH=63 HEIGHT=24 ALIGN=BOTTOM ALT="previous" SRC="../icons/previous_motif.gif"></A> <A NAME="tex2html1785" HREF="page611.html"><IMG WIDTH=43 HEIGHT=24 ALIGN=BOTTOM ALT="index" SRC="../icons/index_motif.gif"></A> <P><ADDRESS><img src="../icons/bruno.gif" alt="Bruno" align=right><a href="../copyright.html">Copyright © 2003</a> by <a href="../signature.html">Bruno R. Preiss, P.Eng.</a> All rights reserved.</ADDRESS></BODY></HTML>
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?