page78.html

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

HTML
65
字号
<HTML><HEAD><TITLE>Checking Your Analysis</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="tex2html2103" HREF="page79.html"><IMG WIDTH=37 HEIGHT=24 ALIGN=BOTTOM ALT="next" SRC="../icons/next_motif.gif"></A> <A NAME="tex2html2101" HREF="page72.html"><IMG WIDTH=26 HEIGHT=24 ALIGN=BOTTOM ALT="up" SRC="../icons/up_motif.gif"></A> <A NAME="tex2html2097" HREF="page77.html"><IMG WIDTH=63 HEIGHT=24 ALIGN=BOTTOM ALT="previous" SRC="../icons/previous_motif.gif"></A>  <A NAME="tex2html2105" HREF="page611.html"><IMG WIDTH=43 HEIGHT=24 ALIGN=BOTTOM ALT="index" SRC="../icons/index_motif.gif"></A> <BR><HR><H2><A NAME="SECTION003460000000000000000">Checking Your Analysis</A></H2><P>Having made an asymptotic analysis of the running time of an algorithm,how can you verify that the implementation of the algorithmperforms as predicted by the analysis?The only practical way to do this is to conduct an experiment--write out the algorithm in the form of a computer program,run the program,and measure its actual running time for various values of the parameter,<I>n</I> say, used to characterize the size of the problem.<P>However, several difficulties immediately arise:<UL><LI>	How do you compare the results of the analysis which,	by definition, only applies asymptotically,	i.e., as <I>n</I> gets arbitrarily large,	with the actual running time of a program which,	of necessity, must be measured for fixed and finite values of <I>n</I>?<LI>	How do you explain it when the results of your analysis	do not agree with the observed behavior of the program?</UL><P>Suppose you have conducted an experiment in whichyou measured the actual running time of a program, <I>T</I>(<I>n</I>),for a number of different values of <I>n</I>.Furthermore, suppose that on the basis of an analysis of the algorithmyou have concluded that the worst-case running time of the program is <I>O</I>(<I>f</I>(<I>n</I>)).How do you tell from the measurements madethat the program behaves as predicted?<P>One way to do this follows directly from the definition of big oh:there exists <I>c</I><I>&gt;</I>0 such that  <IMG WIDTH=92 HEIGHT=24 ALIGN=MIDDLE ALT="tex2html_wrap_inline60213" SRC="img543.gif"  > for all  <IMG WIDTH=47 HEIGHT=22 ALIGN=MIDDLE ALT="tex2html_wrap_inline58525" SRC="img239.gif"  >.This suggests that we shouldcompute the ratio <I>T</I>(<I>n</I>)/<I>f</I>(<I>n</I>) for each of value of <I>n</I> in the experimentand observe how the ratio behaves as <I>n</I> increases.If this ratio diverges, then <I>f</I>(<I>n</I>) is probably too small;if this ratio converges to zero, then <I>f</I>(<I>n</I>) is probably too big;and if the ratio converges to a constant,then the analysis is probably correct.<P>What if <I>f</I>(<I>n</I>) turns out too large?There are several possibilities:<UL><LI>	The function <I>f</I>(<I>n</I>) is not a <em>tight</em> bound.	That is, the analysis is still correct,	but the bound is not the tightest bound possible.<LI>	The analysis was for the <em>worst case</em>	but the worst case did not arise in the set of experiments conducted.<LI>	A mistake was made and the analysis is wrong.</UL><HR><A NAME="tex2html2103" HREF="page79.html"><IMG WIDTH=37 HEIGHT=24 ALIGN=BOTTOM ALT="next" SRC="../icons/next_motif.gif"></A> <A NAME="tex2html2101" HREF="page72.html"><IMG WIDTH=26 HEIGHT=24 ALIGN=BOTTOM ALT="up" SRC="../icons/up_motif.gif"></A> <A NAME="tex2html2097" HREF="page77.html"><IMG WIDTH=63 HEIGHT=24 ALIGN=BOTTOM ALT="previous" SRC="../icons/previous_motif.gif"></A>  <A NAME="tex2html2105" 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 + -
显示快捷键?