⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 page77.html

📁 wqeqwvrw rkjqhwrjwq jkhrjqwhrwq jkhrwq
💻 HTML
📖 第 1 页 / 共 2 页
字号:
	Derive tight, big oh expressions for the running times of
	sum.c,horner.c,factorial.c,findmax.c,geometric.c,geometric2.c,power.c,geometric3.c.<LI>
	Consider the C++ program fragments given below.
	Assume that <tt>n</tt>, <tt>m</tt> and <tt>k</tt>
	are <tt>unsigned int</tt>s and that the functions <tt>e</tt>,
	<tt>f</tt>, <tt>g</tt> and <tt>h</tt> have the following characteristics:
	<UL><LI> The worst case running time for <tt>e(n,m,k)</tt> is <I>O</I>(1)
		and it returns a value between 1 and (<I>n</I>+<I>m</I>+<I>k</I>).<LI> The worst case running time for <tt>f(n,m,k)</tt> is <I>O</I>(<I>n</I>+<I>m</I>).<LI> The worst case running time for <tt>g(n,m,k)</tt> is <I>O</I>(<I>m</I>+<I>k</I>).<LI> The worst case running time for <tt>h(n,m,k)</tt> is <I>O</I>(<I>n</I>+<I>k</I>).
	</UL>
	Determine a tight, big oh expression for the worst-case
	running time of each of the following program fragments:
	<OL><LI>
<PRE>f (n, 10, 0);
g (n, m, k);
h (n, m, 1000000);</PRE><LI>
<PRE>for (unsigned int i = 0; i &lt; n; ++i)
    f (n, m, k);</PRE><LI>
<PRE>for (unsigned int i = 0; i &lt; e (n, 10, 100); ++i)
    f (n, 10, 0);</PRE><LI>
<PRE>for (unsigned int i = 0; i &lt; e (n, m, k); ++i)
    f (n, 10, 0);</PRE><LI>
<PRE>for (unsigned int i = 0; i &lt; n; ++i)
    for (unsigned int j = i; j &lt; n; ++j)
        f (n, m, k);</PRE>
<PRE></PRE>
	</OL><LI> <A NAME="exerciseasymptoticf">&#160;</A>
	Consider the following C++ program fragment.
	What value does <tt>f</tt> compute?
	(Express your answer as a function of <I>n</I>).
	Give a tight, big oh expression for the worst-case
	running time of the function <tt>f</tt>.
<PRE>unsigned int f (unsigned int n)
{
    unsigned int sum = 0;
    for (unsigned int i = 1; i &lt;= n; ++i)
        sum = sum + i;
    return sum;
}</PRE><LI> <A NAME="exerciseasymptoticg">&#160;</A>
	Consider the following C++ program fragment.
	(The function <tt>f</tt> is given in Exercise&nbsp;<A HREF="page77.html#exerciseasymptoticf" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/html/page77.html#exerciseasymptoticf"><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>).
	What value does <tt>g</tt> compute?
	(Express your answer as a function of <I>n</I>).
	Give a tight, big oh expression for the worst-case
	running time of the function <tt>g</tt>.
<PRE>unsigned int g (unsigned int n)
{
    unsigned int sum = 0;
    for (unsigned int i = 1; i &lt;= n; ++i)
        sum = sum + i + f (n);
    return sum;
}</PRE><LI>
	Consider the following C++ program fragment.
	(The function <tt>f</tt> is given in Exercise&nbsp;<A HREF="page77.html#exerciseasymptoticf" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/html/page77.html#exerciseasymptoticf"><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 the function <tt>g</tt> is given in Exercise&nbsp;<A HREF="page77.html#exerciseasymptoticg" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/html/page77.html#exerciseasymptoticg"><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>).
	What value does <tt>h</tt> compute?
	(Express your answer as a function of <I>n</I>).
	Give a tight, big oh expression for the worst-case
	running time of the function <tt>h</tt>.
<PRE>unsigned int h (unsigned int n)
    { return f (n) + g (n); }</PRE>
</OL><HR><A NAME="tex2html2847" HREF="page78.html" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/html/page78.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="tex2html2845" HREF="page56.html" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/html/page56.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="tex2html2839" HREF="page76.html" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/html/page76.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="tex2html2849" 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="tex2html2850" 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 + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -