page39.html

来自「Data Structures And Algorithms With Obje」· HTML 代码 · 共 68 行

HTML
68
字号
<HTML><HEAD><TITLE>A Simple example-Arithmetic 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="tex2html1659" HREF="page40.html"><IMG WIDTH=37 HEIGHT=24 ALIGN=BOTTOM ALT="next" SRC="../icons/next_motif.gif"></A> <A NAME="tex2html1657" HREF="page37.html"><IMG WIDTH=26 HEIGHT=24 ALIGN=BOTTOM ALT="up" SRC="../icons/up_motif.gif"></A> <A NAME="tex2html1651" HREF="page38.html"><IMG WIDTH=63 HEIGHT=24 ALIGN=BOTTOM ALT="previous" SRC="../icons/previous_motif.gif"></A>  <A NAME="tex2html1661" HREF="page611.html"><IMG WIDTH=43 HEIGHT=24 ALIGN=BOTTOM ALT="index" SRC="../icons/index_motif.gif"></A> <BR><HR><H2><A NAME="SECTION002120000000000000000">A Simple example-Arithmetic Series Summation</A></H2><P>In this section we apply Axioms&nbsp;<A HREF="page38.html#axiomi"><IMG  ALIGN=BOTTOM ALT="gif" SRC="../icons/cross_ref_motif.gif"></A>, <A HREF="page38.html#axiomii"><IMG  ALIGN=BOTTOM ALT="gif" SRC="../icons/cross_ref_motif.gif"></A> and&nbsp;<A HREF="page38.html#axiomiii"><IMG  ALIGN=BOTTOM ALT="gif" SRC="../icons/cross_ref_motif.gif"></A>to the analysis of the running time of a program to compute the followingsimple arithmetic series summation<P> <IMG WIDTH=266 HEIGHT=44 ALIGN=BOTTOM ALT="displaymath57669" SRC="img20.gif"  ><P>The algorithm to compute this summation is given in Program&nbsp;<A HREF="page39.html#progexamplea"><IMG  ALIGN=BOTTOM ALT="gif" SRC="../icons/cross_ref_motif.gif"></A>.<P><P><A NAME="647">&#160;</A><A NAME="progexamplea">&#160;</A> <IMG WIDTH=575 HEIGHT=142 ALIGN=BOTTOM ALT="program356" SRC="img22.gif"  ><BR><STRONG>Program:</STRONG> Program to compute  <IMG WIDTH=45 HEIGHT=25 ALIGN=MIDDLE ALT="tex2html_wrap_inline57671" SRC="img21.gif"  >.<BR><P><P>The executable statements in Program&nbsp;<A HREF="page39.html#progexamplea"><IMG  ALIGN=BOTTOM ALT="gif" SRC="../icons/cross_ref_motif.gif"></A>comprise lines&nbsp;2-7.Table&nbsp;<A HREF="page39.html#tblsumc"><IMG  ALIGN=BOTTOM ALT="gif" SRC="../icons/cross_ref_motif.gif"></A> gives the running times of each of these statements.<P><P><A NAME="649">&#160;</A><P>    <A NAME="tblsumc">&#160;</A>    <DIV ALIGN=CENTER><P ALIGN=CENTER><TABLE COLS=3 BORDER FRAME=HSIDES RULES=GROUPS><COL ALIGN=CENTER><COL ALIGN=CENTER><COL ALIGN=LEFT><TBODY><TR><TD VALIGN=BASELINE ALIGN=CENTER NOWRAP>	    statement </TD><TD VALIGN=BASELINE ALIGN=CENTER NOWRAP> time </TD><TD VALIGN=BASELINE ALIGN=CENTER NOWRAP COLSPAN=1> code</TD></TR></TBODY><TBODY><TR><TD VALIGN=BASELINE ALIGN=CENTER NOWRAP>2 </TD><TD VALIGN=BASELINE ALIGN=CENTER NOWRAP>  <IMG WIDTH=88 HEIGHT=18 ALIGN=MIDDLE ALT="tex2html_wrap_inline57639" SRC="img9.gif"  > </TD><TD VALIGN=BASELINE ALIGN=LEFT NOWRAP> <tt>result = 0</tt></TD></TR><TR><TD VALIGN=BASELINE ALIGN=CENTER NOWRAP> 	    3 </TD><TD VALIGN=BASELINE ALIGN=CENTER NOWRAP>  <IMG WIDTH=88 HEIGHT=18 ALIGN=MIDDLE ALT="tex2html_wrap_inline57639" SRC="img9.gif"  > </TD><TD VALIGN=BASELINE ALIGN=LEFT NOWRAP> <tt>i = 1</tt> </TD></TR><TR><TD VALIGN=BASELINE ALIGN=CENTER NOWRAP> 	    4 </TD><TD VALIGN=BASELINE ALIGN=CENTER NOWRAP>  <IMG WIDTH=159 HEIGHT=24 ALIGN=MIDDLE ALT="tex2html_wrap_inline57677" SRC="img23.gif"  > </TD><TD VALIGN=BASELINE ALIGN=LEFT NOWRAP> <tt>i &lt;= n</tt> </TD></TR><TR><TD VALIGN=BASELINE ALIGN=CENTER NOWRAP> 	    5 </TD><TD VALIGN=BASELINE ALIGN=CENTER NOWRAP>  <IMG WIDTH=174 HEIGHT=24 ALIGN=MIDDLE ALT="tex2html_wrap_inline57679" SRC="img24.gif"  > </TD><TD VALIGN=BASELINE ALIGN=LEFT NOWRAP> <tt>result += i</tt> </TD></TR><TR><TD VALIGN=BASELINE ALIGN=CENTER NOWRAP> 	    6 </TD><TD VALIGN=BASELINE ALIGN=CENTER NOWRAP>  <IMG WIDTH=174 HEIGHT=24 ALIGN=MIDDLE ALT="tex2html_wrap_inline57679" SRC="img24.gif"  > </TD><TD VALIGN=BASELINE ALIGN=LEFT NOWRAP> <tt>i += 1</tt> </TD></TR><TR><TD VALIGN=BASELINE ALIGN=CENTER NOWRAP> 	    7 </TD><TD VALIGN=BASELINE ALIGN=CENTER NOWRAP>  <IMG WIDTH=96 HEIGHT=18 ALIGN=MIDDLE ALT="tex2html_wrap_inline57683" SRC="img25.gif"  > </TD><TD VALIGN=BASELINE ALIGN=LEFT NOWRAP> <tt>return result</tt> </TD></TR></TBODY><TBODY><TR><TD VALIGN=BASELINE ALIGN=CENTER NOWRAP>TOTAL </TD><TD VALIGN=BASELINE ALIGN=CENTER NOWRAP>  <IMG WIDTH=227 HEIGHT=24 ALIGN=MIDDLE ALT="tex2html_wrap_inline57685" SRC="img26.gif"  > </TD><TD VALIGN=BASELINE ALIGN=LEFT NOWRAP> </TD></TR><TR><TD VALIGN=BASELINE ALIGN=CENTER NOWRAP> 	    </TD><TD VALIGN=BASELINE ALIGN=CENTER NOWRAP>  <IMG WIDTH=230 HEIGHT=24 ALIGN=MIDDLE ALT="tex2html_wrap_inline57687" SRC="img27.gif"  > </TD><TD VALIGN=BASELINE ALIGN=LEFT NOWRAP> </TD></TR></TBODY><CAPTION ALIGN=BOTTOM><STRONG>Table:</STRONG> Computing the running time of Program&nbsp;<A HREF="page39.html#progexamplea"><IMG  ALIGN=BOTTOM ALT="gif" SRC="../icons/cross_ref_motif.gif"></A>.</CAPTION></TABLE></P></DIV><P><P>Summing the entries in Table&nbsp;<A HREF="page39.html#tblsumc"><IMG  ALIGN=BOTTOM ALT="gif" SRC="../icons/cross_ref_motif.gif"></A>we get that the running time, <I>T</I>(<I>n</I>),of Program&nbsp;<A HREF="page39.html#progexamplea"><IMG  ALIGN=BOTTOM ALT="gif" SRC="../icons/cross_ref_motif.gif"></A> is<P><A NAME="eqnmodelsumc">&#160;</A> <IMG WIDTH=500 HEIGHT=16 ALIGN=BOTTOM ALT="equation387" SRC="img28.gif"  ><P>where  <IMG WIDTH=238 HEIGHT=22 ALIGN=MIDDLE ALT="tex2html_wrap_inline57691" SRC="img29.gif"  >and  <IMG WIDTH=219 HEIGHT=23 ALIGN=MIDDLE ALT="tex2html_wrap_inline57693" SRC="img30.gif"  >.<P><HR><A NAME="tex2html1659" HREF="page40.html"><IMG WIDTH=37 HEIGHT=24 ALIGN=BOTTOM ALT="next" SRC="../icons/next_motif.gif"></A> <A NAME="tex2html1657" HREF="page37.html"><IMG WIDTH=26 HEIGHT=24 ALIGN=BOTTOM ALT="up" SRC="../icons/up_motif.gif"></A> <A NAME="tex2html1651" HREF="page38.html"><IMG WIDTH=63 HEIGHT=24 ALIGN=BOTTOM ALT="previous" SRC="../icons/previous_motif.gif"></A>  <A NAME="tex2html1661" 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 &#169; 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 + -
显示快捷键?