page379.html

来自「wqeqwvrw rkjqhwrjwq jkhrjqwhrwq jkhrwq」· HTML 代码 · 共 84 行 · 第 1/2 页

HTML
84
字号
to <tt>this</tt> binomial queue.
<P>
<P><A NAME="27721">&#160;</A><A NAME="progbinom4c">&#160;</A> <IMG WIDTH=575 HEIGHT=525 ALIGN=BOTTOM ALT="program27585" SRC="img1564.gif" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/html/img1564.gif"  ><BR>
<STRONG>Program:</STRONG> <tt>BinomialQueue</tt> Class 	<tt>Merge</tt> Member Function Definition<BR>
<P>
<P>
Each iteration of the main loop of the algorithm (lines&nbsp;12-24)
computes the  <IMG WIDTH=17 HEIGHT=13 ALIGN=BOTTOM ALT="tex2html_wrap_inline58387" SRC="img77.gif" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/html/img77.gif"  > ``bit'' of the result--the  <IMG WIDTH=17 HEIGHT=13 ALIGN=BOTTOM ALT="tex2html_wrap_inline58387" SRC="img77.gif" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/html/img77.gif"  > bit is a binomial tree of order <I>i</I>.
At most three terms need to be considered:
the carry from the preceding iteration and two  <IMG WIDTH=15 HEIGHT=23 ALIGN=MIDDLE ALT="tex2html_wrap_inline66836" SRC="img1539.gif" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/html/img1539.gif"  >s, one from each of the queues that are being merged.
<P>
Two functions, <tt>Sum</tt> and <tt>Carry</tt>,
compute the result required in each iteration.
Program&nbsp;<A HREF="page379.html#progbinom5c" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/html/page379.html#progbinom5c"><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> defines both <tt>Sum</tt> and <tt>Carry</tt>.
Notice that the <tt>Sum</tt> function simply
selects and returns one of its arguments.
Therefore, the running time for <tt>Sum</tt> is clearly <I>O</I>(1).
<P>
<P><A NAME="27725">&#160;</A><A NAME="progbinom5c">&#160;</A> <IMG WIDTH=575 HEIGHT=563 ALIGN=BOTTOM ALT="program27603" SRC="img1565.gif" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/html/img1565.gif"  ><BR>
<STRONG>Program:</STRONG> <tt>BinomialQueue</tt> Class 	<tt>Sum</tt> and <tt>Carry</tt> Member Function Definitions<BR>
<P>
<P>
In the worst case,
the <tt>Carry</tt> function calls the <tt>Add</tt> function
to combine two <tt>BinomialTree</tt>s into one.
Therefore, the worst-case running time for <tt>Carry</tt> is
<P> <IMG WIDTH=341 HEIGHT=17 ALIGN=BOTTOM ALT="displaymath66932" SRC="img1558.gif" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/html/img1558.gif"  ><P>
<P>
Suppose the <tt>Merge</tt> routine of Program&nbsp;<A HREF="page379.html#progbinom4c" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/html/page379.html#progbinom4c"><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> is
used to combine a binomial queue with <I>n</I> items with another
that contains <I>m</I> items.
Since the resulting priority queue contains <I>n</I>+<I>m</I> items,
there are at most  <IMG WIDTH=121 HEIGHT=26 ALIGN=MIDDLE ALT="tex2html_wrap_inline67046" SRC="img1566.gif" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/html/img1566.gif"  > binomial trees in the result.
Thus, the running time for the <tt>Merge</tt> operation is
<P> <IMG WIDTH=435 HEIGHT=17 ALIGN=BOTTOM ALT="displaymath66961" SRC="img1567.gif" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/html/img1567.gif"  ><P><HR><A NAME="tex2html6613" HREF="page380.html" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/html/page380.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="tex2html6611" HREF="page370.html" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/html/page370.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="tex2html6605" HREF="page378.html" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/html/page378.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="tex2html6615" 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="tex2html6616" 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 + =
减小字号Ctrl + -
显示快捷键?