page76.html
来自「wqeqwvrw rkjqhwrjwq jkhrjqwhrwq jkhrwq」· HTML 代码 · 共 65 行
HTML
65 行
<HTML>
<HEAD>
<TITLE>Checking Your Analysis</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="tex2html2835" HREF="page77.html" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/html/page77.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="tex2html2833" HREF="page70.html" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/html/page70.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="tex2html2829" HREF="page75.html" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/html/page75.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="tex2html2837" 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="tex2html2838" 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="SECTION004460000000000000000">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 algorithm
performs 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,
compile and execute 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 which
you 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 algorithm
you 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 made
that the program behaves as predicted?
<P>
One way to do this follows directly from the definition of big oh:
<IMG WIDTH=212 HEIGHT=24 ALIGN=MIDDLE ALT="tex2html_wrap_inline60747" SRC="img548.gif" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/html/img548.gif" >.
This suggests that we should
compute the ratio <I>T</I>(<I>n</I>)/<I>f</I>(<I>n</I>) for each of value of <I>n</I> in the experiment
and 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 to large?
There are several possibilities:
<UL><LI>
The function <I>f</I>(<I>n</I>) is not a <em>tight</em> bound.
I.e., 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="tex2html2835" HREF="page77.html" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/html/page77.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="tex2html2833" HREF="page70.html" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/html/page70.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="tex2html2829" HREF="page75.html" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/html/page75.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="tex2html2837" 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="tex2html2838" 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 © 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 + -
显示快捷键?