📄 page346.html
字号:
<HTML><HEAD><TITLE>Running Time Analysis</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="tex2html5176" HREF="page347.html"><IMG WIDTH=37 HEIGHT=24 ALIGN=BOTTOM ALT="next" SRC="../icons/next_motif.gif"></A> <A NAME="tex2html5174" HREF="page344.html"><IMG WIDTH=26 HEIGHT=24 ALIGN=BOTTOM ALT="up" SRC="../icons/up_motif.gif"></A> <A NAME="tex2html5170" HREF="page345.html"><IMG WIDTH=63 HEIGHT=24 ALIGN=BOTTOM ALT="previous" SRC="../icons/previous_motif.gif"></A> <A NAME="tex2html5178" HREF="page611.html"><IMG WIDTH=43 HEIGHT=24 ALIGN=BOTTOM ALT="index" SRC="../icons/index_motif.gif"></A> <BR><HR><H3><A NAME="SECTION0010722000000000000000">Running Time Analysis</A></H3><P>The running time of the downward pass of the insertion algorithmis identical to that of an unsuccessful search(assuming the item to be inserted is not already in the tree).That is, for a B-tree of height <I>h</I>,the worst-case running time of the downward pass is <P> <IMG WIDTH=414 HEIGHT=16 ALIGN=BOTTOM ALT="displaymath65179" SRC="img1355.gif" ><P><P>The second pass of the insertion algorithm does the insertionand balances the tree if necessary.In the worst case,all of the nodes in the insertion path up to the root need to be balanced.Each time the <tt>insertUp</tt> method is invoked,it calls <tt>findIndex</tt> which has running time <IMG WIDTH=264 HEIGHT=24 ALIGN=MIDDLE ALT="tex2html_wrap_inline65187" SRC="img1356.gif" > in the worst case.The additional time required to balance a node is <I>O</I>(<I>M</I>).Therefore, the worst-case running time of the upward pass is<P> <IMG WIDTH=401 HEIGHT=16 ALIGN=BOTTOM ALT="displaymath65180" SRC="img1357.gif" ><P><P>Therefore, the total running time for insertion is<P> <IMG WIDTH=405 HEIGHT=16 ALIGN=BOTTOM ALT="displaymath65181" SRC="img1358.gif" ><P>According to Theorem <A HREF="page340.html#theoremsrchtreeiii"><IMG ALIGN=BOTTOM ALT="gif" SRC="../icons/cross_ref_motif.gif"></A>,the height of a B-tree is <IMG WIDTH=165 HEIGHT=24 ALIGN=MIDDLE ALT="tex2html_wrap_inline65191" SRC="img1359.gif" >,where <I>n</I> is the number of keys in the B-tree.If we assume that two keys can be compared in constant time,i.e., <IMG WIDTH=96 HEIGHT=24 ALIGN=MIDDLE ALT="tex2html_wrap_inline64143" SRC="img1239.gif" >,then the running time for insertion in a B-tree is simply <IMG WIDTH=75 HEIGHT=24 ALIGN=MIDDLE ALT="tex2html_wrap_inline65197" SRC="img1360.gif" >.<P><HR><A NAME="tex2html5176" HREF="page347.html"><IMG WIDTH=37 HEIGHT=24 ALIGN=BOTTOM ALT="next" SRC="../icons/next_motif.gif"></A> <A NAME="tex2html5174" HREF="page344.html"><IMG WIDTH=26 HEIGHT=24 ALIGN=BOTTOM ALT="up" SRC="../icons/up_motif.gif"></A> <A NAME="tex2html5170" HREF="page345.html"><IMG WIDTH=63 HEIGHT=24 ALIGN=BOTTOM ALT="previous" SRC="../icons/previous_motif.gif"></A> <A NAME="tex2html5178" 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 © 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 + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -