📄 page41.html
字号:
<HTML><HEAD><TITLE>Another example-Horner's Rule</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="tex2html1681" HREF="page42.html"><IMG WIDTH=37 HEIGHT=24 ALIGN=BOTTOM ALT="next" SRC="../icons/next_motif.gif"></A> <A NAME="tex2html1679" HREF="page37.html"><IMG WIDTH=26 HEIGHT=24 ALIGN=BOTTOM ALT="up" SRC="../icons/up_motif.gif"></A> <A NAME="tex2html1673" HREF="page40.html"><IMG WIDTH=63 HEIGHT=24 ALIGN=BOTTOM ALT="previous" SRC="../icons/previous_motif.gif"></A> <A NAME="tex2html1683" HREF="page611.html"><IMG WIDTH=43 HEIGHT=24 ALIGN=BOTTOM ALT="index" SRC="../icons/index_motif.gif"></A> <BR><HR><H2><A NAME="SECTION002140000000000000000">Another example-Horner's Rule</A></H2><A NAME="secmodelhorner"> </A><P>In this section we apply Axioms <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>, <A HREF="page38.html#axiomiii"><IMG ALIGN=BOTTOM ALT="gif" SRC="../icons/cross_ref_motif.gif"></A> and <A HREF="page38.html#axiomiv"><IMG ALIGN=BOTTOM ALT="gif" SRC="../icons/cross_ref_motif.gif"></A>to the analysis of the running time of a programwhich evaluates the value of a polynomial.That is, given the <I>n</I>+1 coefficients <IMG WIDTH=91 HEIGHT=14 ALIGN=MIDDLE ALT="tex2html_wrap_inline57703" SRC="img33.gif" >,and a value <I>x</I>, we wish to compute the following summation<P> <IMG WIDTH=278 HEIGHT=44 ALIGN=BOTTOM ALT="displaymath57699" SRC="img34.gif" ><P><P>The usual way to evaluate suchpolynomials is to use Horner's rule<A NAME=409> </A>,which is an algorithm to compute the summation withoutrequiring the computation of arbitrary powers of <I>x</I>.The algorithm to compute this summation is given in Program <A HREF="page41.html#progexampleb"><IMG ALIGN=BOTTOM ALT="gif" SRC="../icons/cross_ref_motif.gif"></A>.Table <A HREF="page41.html#tblhornerc"><IMG ALIGN=BOTTOM ALT="gif" SRC="../icons/cross_ref_motif.gif"></A> gives the running times of each of theexecutable statements in Program <A HREF="page41.html#progexampleb"><IMG ALIGN=BOTTOM ALT="gif" SRC="../icons/cross_ref_motif.gif"></A>.<P><P><A NAME="650"> </A><A NAME="progexampleb"> </A> <IMG WIDTH=575 HEIGHT=142 ALIGN=BOTTOM ALT="program413" SRC="img36.gif" ><BR><STRONG>Program:</STRONG> Program to compute <IMG WIDTH=67 HEIGHT=27 ALIGN=MIDDLE ALT="tex2html_wrap_inline57709" SRC="img35.gif" > using Horner's rule.<BR><P><P><P><A NAME="652"> </A><P> <A NAME="tblhornerc"> </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> <IMG WIDTH=135 HEIGHT=21 ALIGN=MIDDLE ALT="tex2html_wrap_inline57697" SRC="img32.gif" > </TD></TR><TR><TD VALIGN=BASELINE ALIGN=CENTER NOWRAP> 3 </TD><TD VALIGN=BASELINE ALIGN=CENTER NOWRAP> <IMG WIDTH=132 HEIGHT=20 ALIGN=MIDDLE ALT="tex2html_wrap_inline57713" SRC="img37.gif" > </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></TR><TR><TD VALIGN=BASELINE ALIGN=CENTER NOWRAP> 5 </TD><TD VALIGN=BASELINE ALIGN=CENTER NOWRAP> <IMG WIDTH=250 HEIGHT=24 ALIGN=MIDDLE ALT="tex2html_wrap_inline57717" SRC="img38.gif" > </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_inline57719" SRC="img39.gif" > </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></TR></TBODY><TBODY><TR><TD VALIGN=BASELINE ALIGN=CENTER NOWRAP>TOTAL </TD><TD VALIGN=BASELINE ALIGN=CENTER NOWRAP> <IMG WIDTH=333 HEIGHT=24 ALIGN=MIDDLE ALT="tex2html_wrap_inline57723" SRC="img40.gif" > </TD></TR><TR><TD VALIGN=BASELINE ALIGN=CENTER NOWRAP> </TD><TD VALIGN=BASELINE ALIGN=CENTER NOWRAP> <IMG WIDTH=307 HEIGHT=24 ALIGN=MIDDLE ALT="tex2html_wrap_inline57725" SRC="img41.gif" > </TD></TR></TBODY><CAPTION ALIGN=BOTTOM><STRONG>Table:</STRONG> Computing the running time of Program <A HREF="page41.html#progexampleb"><IMG ALIGN=BOTTOM ALT="gif" SRC="../icons/cross_ref_motif.gif"></A>.</CAPTION></TABLE></P></DIV><P><P>Summing the entries in Table <A HREF="page41.html#tblhornerc"><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 <A HREF="page41.html#progexampleb"><IMG ALIGN=BOTTOM ALT="gif" SRC="../icons/cross_ref_motif.gif"></A> is<P><A NAME="eqnmodelhornerc"> </A> <IMG WIDTH=500 HEIGHT=16 ALIGN=BOTTOM ALT="equation433" SRC="img42.gif" ><P>where <IMG WIDTH=315 HEIGHT=21 ALIGN=MIDDLE ALT="tex2html_wrap_inline57729" SRC="img43.gif" >and <IMG WIDTH=325 HEIGHT=21 ALIGN=MIDDLE ALT="tex2html_wrap_inline57731" SRC="img44.gif" >.<P><HR><A NAME="tex2html1681" HREF="page42.html"><IMG WIDTH=37 HEIGHT=24 ALIGN=BOTTOM ALT="next" SRC="../icons/next_motif.gif"></A> <A NAME="tex2html1679" HREF="page37.html"><IMG WIDTH=26 HEIGHT=24 ALIGN=BOTTOM ALT="up" SRC="../icons/up_motif.gif"></A> <A NAME="tex2html1673" HREF="page40.html"><IMG WIDTH=63 HEIGHT=24 ALIGN=BOTTOM ALT="previous" SRC="../icons/previous_motif.gif"></A> <A NAME="tex2html1683" 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 + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -