page39.html

来自「wqeqwvrw rkjqhwrjwq jkhrjqwhrwq jkhrwq」· HTML 代码 · 共 74 行

HTML
74
字号
<HTML>
<HEAD>
<TITLE>Another Example-Horner's Rule</TITLE>
</HEAD>
<BODY bgcolor="#FFFFFF">
 <img src="cover75.gif" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/icons/cover75.gif" alt="Logo" align=right>
<b>Data Structures and Algorithms 
with Object-Oriented Design Patterns in C++</b><br>
<A NAME="tex2html2376" HREF="page40.html" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/html/page40.html"><IMG WIDTH=37 HEIGHT=24 ALIGN=BOTTOM ALT="next" SRC="next_motif.gif" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/icons/next_motif.gif"></A> <A NAME="tex2html2374" HREF="page35.html" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/html/page35.html"><IMG WIDTH=26 HEIGHT=24 ALIGN=BOTTOM ALT="up" SRC="up_motif.gif" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/icons/up_motif.gif"></A> <A NAME="tex2html2368" HREF="page38.html" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/html/page38.html"><IMG WIDTH=63 HEIGHT=24 ALIGN=BOTTOM ALT="previous" SRC="previous_motif.gif" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/icons/previous_motif.gif"></A> <A NAME="tex2html2378" HREF="page9.html" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/html/page9.html"><IMG WIDTH=65 HEIGHT=24 ALIGN=BOTTOM ALT="contents" SRC="contents_motif.gif" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/icons/contents_motif.gif"></A> <A NAME="tex2html2379" HREF="page620.html" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/html/page620.html"><IMG WIDTH=43 HEIGHT=24 ALIGN=BOTTOM ALT="index" SRC="index_motif.gif" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/icons/index_motif.gif"></A> <BR><HR>
<H2><A NAME="SECTION003140000000000000000">Another Example-Horner's Rule</A></H2>
<A NAME="secmodelhorner">&#160;</A>
<P>
In this section we apply Axioms&nbsp;<A HREF="page36.html#axiomi" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/html/page36.html#axiomi"><IMG  ALIGN=BOTTOM ALT="gif" SRC="cross_ref_motif.gif" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/icons/cross_ref_motif.gif"></A>, <A HREF="page36.html#axiomii" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/html/page36.html#axiomii"><IMG  ALIGN=BOTTOM ALT="gif" SRC="cross_ref_motif.gif" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/icons/cross_ref_motif.gif"></A>, <A HREF="page36.html#axiomiii" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/html/page36.html#axiomiii"><IMG  ALIGN=BOTTOM ALT="gif" SRC="cross_ref_motif.gif" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/icons/cross_ref_motif.gif"></A> and&nbsp;<A HREF="page36.html#axiomiv" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/html/page36.html#axiomiv"><IMG  ALIGN=BOTTOM ALT="gif" SRC="cross_ref_motif.gif" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/icons/cross_ref_motif.gif"></A>
to the analysis of the running time of a program
which evaluates the value of a polynomial.
I.e., given the <I>n</I>+1 coefficients  <IMG WIDTH=91 HEIGHT=14 ALIGN=MIDDLE ALT="tex2html_wrap_inline58245" SRC="img33.gif" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/html/img33.gif"  >,
and a value <I>x</I>, we wish to compute the following summation
<P> <IMG WIDTH=278 HEIGHT=43 ALIGN=BOTTOM ALT="displaymath58241" SRC="img34.gif" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/html/img34.gif"  ><P>
<P>
The usual way to evaluate such
polynomials is to use Horner's rule<A NAME=390>&#160;</A>,
which is an algorithm to compute the summation without
requiring the computation of arbitrary powers of <I>x</I>.
The algorithm to compute this summation is given in Program&nbsp;<A HREF="page39.html#proghornerc" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/html/page39.html#proghornerc"><IMG  ALIGN=BOTTOM ALT="gif" SRC="cross_ref_motif.gif" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/icons/cross_ref_motif.gif"></A>.
Table&nbsp;<A HREF="page39.html#tblhornerc" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/html/page39.html#tblhornerc"><IMG  ALIGN=BOTTOM ALT="gif" SRC="cross_ref_motif.gif" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/icons/cross_ref_motif.gif"></A> gives the running times of each of the
executable statements in Program&nbsp;<A HREF="page39.html#proghornerc" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/html/page39.html#proghornerc"><IMG  ALIGN=BOTTOM ALT="gif" SRC="cross_ref_motif.gif" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/icons/cross_ref_motif.gif"></A>.
<P>
<P><A NAME="619">&#160;</A><A NAME="proghornerc">&#160;</A> <IMG WIDTH=575 HEIGHT=143 ALIGN=BOTTOM ALT="program394" SRC="img36.gif" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/html/img36.gif"  ><BR>
<STRONG>Program:</STRONG> Program to compute  <IMG WIDTH=66 HEIGHT=27 ALIGN=MIDDLE ALT="tex2html_wrap_inline58251" SRC="img35.gif" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/html/img35.gif"  > using Horner's rule<BR>
<P>
<P>
<P><A NAME="621">&#160;</A>
<P>
    <A NAME="tblhornerc">&#160;</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>3 </TD><TD VALIGN=BASELINE ALIGN=CENTER NOWRAP>  <IMG WIDTH=134 HEIGHT=22 ALIGN=MIDDLE ALT="tex2html_wrap_inline58239" SRC="img32.gif" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/html/img32.gif"  > </TD></TR>
<TR><TD VALIGN=BASELINE ALIGN=CENTER NOWRAP> 
	    4a </TD><TD VALIGN=BASELINE ALIGN=CENTER NOWRAP>  <IMG WIDTH=132 HEIGHT=21 ALIGN=MIDDLE ALT="tex2html_wrap_inline58255" SRC="img37.gif" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/html/img37.gif"  > </TD></TR>
<TR><TD VALIGN=BASELINE ALIGN=CENTER NOWRAP> 
	    4b </TD><TD VALIGN=BASELINE ALIGN=CENTER NOWRAP>  <IMG WIDTH=159 HEIGHT=24 ALIGN=MIDDLE ALT="tex2html_wrap_inline58219" SRC="img23.gif" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/html/img23.gif"  > </TD></TR>
<TR><TD VALIGN=BASELINE ALIGN=CENTER NOWRAP> 
	    4c </TD><TD VALIGN=BASELINE ALIGN=CENTER NOWRAP>  <IMG WIDTH=174 HEIGHT=24 ALIGN=MIDDLE ALT="tex2html_wrap_inline58259" SRC="img38.gif" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/html/img38.gif"  > </TD></TR>
<TR><TD VALIGN=BASELINE ALIGN=CENTER NOWRAP> 
	    5 </TD><TD VALIGN=BASELINE ALIGN=CENTER NOWRAP>  <IMG WIDTH=251 HEIGHT=25 ALIGN=MIDDLE ALT="tex2html_wrap_inline58261" SRC="img39.gif" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/html/img39.gif"  > </TD></TR>
<TR><TD VALIGN=BASELINE ALIGN=CENTER NOWRAP> 
	    6 </TD><TD VALIGN=BASELINE ALIGN=CENTER NOWRAP>  <IMG WIDTH=96 HEIGHT=20 ALIGN=MIDDLE ALT="tex2html_wrap_inline58225" SRC="img25.gif" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/html/img25.gif"  > </TD></TR>
</TBODY><TBODY>
<TR><TD VALIGN=BASELINE ALIGN=CENTER NOWRAP>TOTAL </TD><TD VALIGN=BASELINE ALIGN=CENTER NOWRAP>  <IMG WIDTH=333 HEIGHT=25 ALIGN=MIDDLE ALT="tex2html_wrap_inline58265" SRC="img40.gif" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/html/img40.gif"  > </TD></TR>
<TR><TD VALIGN=BASELINE ALIGN=CENTER NOWRAP> 
	    </TD><TD VALIGN=BASELINE ALIGN=CENTER NOWRAP>  <IMG WIDTH=308 HEIGHT=25 ALIGN=MIDDLE ALT="tex2html_wrap_inline58267" SRC="img41.gif" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/html/img41.gif"  > </TD></TR>
</TBODY>
<CAPTION ALIGN=BOTTOM><STRONG>Table:</STRONG> Computing the running time of Program&nbsp;<A HREF="page39.html#proghornerc" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/html/page39.html#proghornerc"><IMG  ALIGN=BOTTOM ALT="gif" SRC="cross_ref_motif.gif" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/icons/cross_ref_motif.gif"></A></CAPTION></TABLE>
</P></DIV><P>
<P>
Summing the entries in Table&nbsp;<A HREF="page39.html#tblhornerc" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/html/page39.html#tblhornerc"><IMG  ALIGN=BOTTOM ALT="gif" SRC="cross_ref_motif.gif" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/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#proghornerc" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/html/page39.html#proghornerc"><IMG  ALIGN=BOTTOM ALT="gif" SRC="cross_ref_motif.gif" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/icons/cross_ref_motif.gif"></A> is
<P><A NAME="eqnmodelhornerc">&#160;</A> <IMG WIDTH=500 HEIGHT=16 ALIGN=BOTTOM ALT="equation414" SRC="img42.gif" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/html/img42.gif"  ><P>
where  <IMG WIDTH=315 HEIGHT=22 ALIGN=MIDDLE ALT="tex2html_wrap_inline58271" SRC="img43.gif" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/html/img43.gif"  >
and  <IMG WIDTH=324 HEIGHT=22 ALIGN=MIDDLE ALT="tex2html_wrap_inline58273" SRC="img44.gif" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/html/img44.gif"  >.
<P>
<HR><A NAME="tex2html2376" HREF="page40.html" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/html/page40.html"><IMG WIDTH=37 HEIGHT=24 ALIGN=BOTTOM ALT="next" SRC="next_motif.gif" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/icons/next_motif.gif"></A> <A NAME="tex2html2374" HREF="page35.html" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/html/page35.html"><IMG WIDTH=26 HEIGHT=24 ALIGN=BOTTOM ALT="up" SRC="up_motif.gif" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/icons/up_motif.gif"></A> <A NAME="tex2html2368" HREF="page38.html" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/html/page38.html"><IMG WIDTH=63 HEIGHT=24 ALIGN=BOTTOM ALT="previous" SRC="previous_motif.gif" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/icons/previous_motif.gif"></A> <A NAME="tex2html2378" HREF="page9.html" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/html/page9.html"><IMG WIDTH=65 HEIGHT=24 ALIGN=BOTTOM ALT="contents" SRC="contents_motif.gif" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/icons/contents_motif.gif"></A> <A NAME="tex2html2379" HREF="page620.html" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/html/page620.html"><IMG WIDTH=43 HEIGHT=24 ALIGN=BOTTOM ALT="index" SRC="index_motif.gif" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/icons/index_motif.gif"></A> <P><ADDRESS>
<img src="bruno.gif" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/icons/bruno.gif" alt="Bruno" align=right>
<a href="javascript:if(confirm('http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/copyright.html  \n\nThis file was not retrieved by Teleport Pro, because it is addressed on a domain or path outside the boundaries set for its Starting Address.  \n\nDo you want to open it from the server?'))window.location='http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/copyright.html'" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/copyright.html">Copyright &#169; 1997</a> by <a href="javascript:if(confirm('http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/signature.html  \n\nThis file was not retrieved by Teleport Pro, because it is addressed on a domain or path outside the boundaries set for its Starting Address.  \n\nDo you want to open it from the server?'))window.location='http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/signature.html'" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/signature.html">Bruno R. Preiss, P.Eng.</a>  All rights reserved.

</ADDRESS>
</BODY>
</HTML>

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?