page377.html

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

HTML
49
字号
<HTML><HEAD><TITLE>getMinTree and getMin Methods</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="tex2html5533" HREF="page378.html"><IMG WIDTH=37 HEIGHT=24 ALIGN=BOTTOM ALT="next" SRC="../icons/next_motif.gif"></A> <A NAME="tex2html5531" HREF="page371.html"><IMG WIDTH=26 HEIGHT=24 ALIGN=BOTTOM ALT="up" SRC="../icons/up_motif.gif"></A> <A NAME="tex2html5527" HREF="page376.html"><IMG WIDTH=63 HEIGHT=24 ALIGN=BOTTOM ALT="previous" SRC="../icons/previous_motif.gif"></A>  <A NAME="tex2html5535" HREF="page611.html"><IMG WIDTH=43 HEIGHT=24 ALIGN=BOTTOM ALT="index" SRC="../icons/index_motif.gif"></A> <BR><HR><H3><A NAME="SECTION0011436000000000000000"><tt>getMinTree</tt> and <tt>getMin</tt> Methods</A></H3><P>A binomial queue that contains <I>n</I> items consists ofat most  <IMG WIDTH=86 HEIGHT=24 ALIGN=MIDDLE ALT="tex2html_wrap_inline66325" SRC="img1508.gif"  > binomial trees.Each of these binomial trees is heap ordered.In particular, the smallest key in each binomial treeis at the root of that tree.So, we know that the smallest key in the queueis found at the root of one of the binomial trees,but we do not know which tree it is.<P>The <tt>getMinTree</tt> method returns thethe binomial tree in the queue that has the smallest root.As shown in Program&nbsp;<A HREF="page377.html#progbinomialQueuec"><IMG  ALIGN=BOTTOM ALT="gif" SRC="../icons/cross_ref_motif.gif"></A>,the <tt>getMinTree</tt> simply traverses the entire linked listto find the tree with the smallest key at its root.Since there are at most  <IMG WIDTH=86 HEIGHT=24 ALIGN=MIDDLE ALT="tex2html_wrap_inline66325" SRC="img1508.gif"  > binomial trees,the worst-case running time of <tt>getMinTree</tt> is<P> <IMG WIDTH=382 HEIGHT=16 ALIGN=BOTTOM ALT="displaymath66329" SRC="img1509.gif"  ><P><P><P><A NAME="27131">&#160;</A><A NAME="progbinomialQueuec">&#160;</A> <IMG WIDTH=575 HEIGHT=409 ALIGN=BOTTOM ALT="program26962" SRC="img1510.gif"  ><BR><STRONG>Program:</STRONG> <tt>BinomialQueue</tt> class <tt>getMinTree</tt> and <tt>getMin</tt> methods.<BR><P><P>Program&nbsp;<A HREF="page377.html#progbinomialQueuec"><IMG  ALIGN=BOTTOM ALT="gif" SRC="../icons/cross_ref_motif.gif"></A> also definesthe <tt>getMin</tt> methodthat returns the smallest key in the priority queue.The <tt>getMin</tt> method uses the <tt>minTree</tt> property to locate thetree with the smallest key at its root and returns that key.Clearly, the asymptotic running time of the <tt>getMin</tt> accessor is the sameas that of the <tt>getMinTree</tt> method.<P><HR><A NAME="tex2html5533" HREF="page378.html"><IMG WIDTH=37 HEIGHT=24 ALIGN=BOTTOM ALT="next" SRC="../icons/next_motif.gif"></A> <A NAME="tex2html5531" HREF="page371.html"><IMG WIDTH=26 HEIGHT=24 ALIGN=BOTTOM ALT="up" SRC="../icons/up_motif.gif"></A> <A NAME="tex2html5527" HREF="page376.html"><IMG WIDTH=63 HEIGHT=24 ALIGN=BOTTOM ALT="previous" SRC="../icons/previous_motif.gif"></A>  <A NAME="tex2html5535" 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 + -
显示快捷键?