page109.html

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

HTML
68
字号
<HTML><HEAD><TITLE>Exercises</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="tex2html2465" HREF="page110.html"><IMG WIDTH=37 HEIGHT=24 ALIGN=BOTTOM ALT="next" SRC="../icons/next_motif.gif"></A> <A NAME="tex2html2463" HREF="page81.html"><IMG WIDTH=26 HEIGHT=24 ALIGN=BOTTOM ALT="up" SRC="../icons/up_motif.gif"></A> <A NAME="tex2html2457" HREF="page108.html"><IMG WIDTH=63 HEIGHT=24 ALIGN=BOTTOM ALT="previous" SRC="../icons/previous_motif.gif"></A>  <A NAME="tex2html2467" HREF="page611.html"><IMG WIDTH=43 HEIGHT=24 ALIGN=BOTTOM ALT="index" SRC="../icons/index_motif.gif"></A> <BR><HR><H1><A NAME="SECTION004400000000000000000">Exercises</A></H1><P><OL><LI>	<OL><LI>		How much space does the <tt>Array</tt> class		declared in Program&nbsp;<A HREF="page84.html#progarraya"><IMG  ALIGN=BOTTOM ALT="gif" SRC="../icons/cross_ref_motif.gif"></A> use to store		an array of <tt>IntType</tt>s of length <I>N</I>?<LI>		How much space does the <tt>LinkedList</tt> class		declared in Program&nbsp;<A HREF="page100.html#proglinkedListb"><IMG  ALIGN=BOTTOM ALT="gif" SRC="../icons/cross_ref_motif.gif"></A> use to store		a list of <I>n</I> <tt>IntType</tt>s?<LI>		For what value of <I>N</I>/<I>n</I> do the two classes use		the same amount of space?	</OL><LI>	The array subscripting methods defined in Program&nbsp;<A HREF="page88.html#progarraye"><IMG  ALIGN=BOTTOM ALT="gif" SRC="../icons/cross_ref_motif.gif"></A>	don't test explicitly the index expression	to see if it is in the proper range.	Explain why the test is not required in this implementation.<LI>	The <tt>baseIndex</tt> property <tt>setBaseIndex</tt> accessor	of the <tt>Array</tt> class	defined in Program&nbsp;<A HREF="page88.html#progarraye"><IMG  ALIGN=BOTTOM ALT="gif" SRC="../icons/cross_ref_motif.gif"></A> simply changes the value	of the <tt>baseIndex</tt> instance attribute.	As a result, after the base is changed,	all the array elements appear to have moved.	How might the method be modified so that the elements of the array	don't change their apparent locations when the base is changed?<LI>	Equation&nbsp;<A HREF="page90.html#eqnfdsaddress"><IMG  ALIGN=BOTTOM ALT="gif" SRC="../icons/cross_ref_motif.gif"></A> is only correct if the subscript	ranges in each dimension start at zero.	How does the formula change when each dimension	is allowed to have an arbitrary subscript range?<LI>	The alternative to <em>row-major</em> layout of of multi-dimensional	arrays is called <em>column-major order</em><A NAME=4056>&#160;</A>.	In column-major layout the leftmost subscript	expression increases fastest.	For example, the elements of the columns of a two-dimensional matrix	end up stored in contiguous memory locations.	Modify Equation&nbsp;<A HREF="page90.html#eqnfdsaddress"><IMG  ALIGN=BOTTOM ALT="gif" SRC="../icons/cross_ref_motif.gif"></A> to compute the correct position	for column-major layout.<LI>	Write a <tt>plus</tt> method for the	<tt>DenseMatrix</tt> class defined in Program&nbsp;<A HREF="page95.html#progdenseMatrixa"><IMG  ALIGN=BOTTOM ALT="gif" SRC="../icons/cross_ref_motif.gif"></A>	that implements the usual matrix addition semantics.<LI>	Which methods are affected if we drop the <tt>_tail</tt> member	variable from the <tt>LinkedList</tt> class.	Determine new running times for the affected methods.<LI>	How does the implementation of the <tt>prepend</tt> method	of the <tt>LinkedList</tt> class defined in Program&nbsp;<A HREF="page104.html#proglinkedListf"><IMG  ALIGN=BOTTOM ALT="gif" SRC="../icons/cross_ref_motif.gif"></A>	change when a circular list with a	sentinel is used as shown in Figure&nbsp;<A HREF="page97.html#figlinklist1"><IMG  ALIGN=BOTTOM ALT="gif" SRC="../icons/cross_ref_motif.gif"></A>&nbsp;(c).<LI>	How does the implementation of the <tt>append</tt> method	of the <tt>LinkedList</tt> class defined in Program&nbsp;<A HREF="page105.html#proglinkedListg"><IMG  ALIGN=BOTTOM ALT="gif" SRC="../icons/cross_ref_motif.gif"></A>	change when a circular list with a	sentinel is used as shown in Figure&nbsp;<A HREF="page97.html#figlinklist1"><IMG  ALIGN=BOTTOM ALT="gif" SRC="../icons/cross_ref_motif.gif"></A>&nbsp;(c).</OL><HR><A NAME="tex2html2465" HREF="page110.html"><IMG WIDTH=37 HEIGHT=24 ALIGN=BOTTOM ALT="next" SRC="../icons/next_motif.gif"></A> <A NAME="tex2html2463" HREF="page81.html"><IMG WIDTH=26 HEIGHT=24 ALIGN=BOTTOM ALT="up" SRC="../icons/up_motif.gif"></A> <A NAME="tex2html2457" HREF="page108.html"><IMG WIDTH=63 HEIGHT=24 ALIGN=BOTTOM ALT="previous" SRC="../icons/previous_motif.gif"></A>  <A NAME="tex2html2467" 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 + -
显示快捷键?