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

📄 page340.html

📁 Data Structures And Algorithms With Object-Oriented Design Patterns In Python (2003) source code and
💻 HTML
字号:
<HTML><HEAD><TITLE>B-Trees</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="tex2html5107" HREF="page341.html"><IMG WIDTH=37 HEIGHT=24 ALIGN=BOTTOM ALT="next" SRC="../icons/next_motif.gif"></A> <A NAME="tex2html5105" HREF="page298.html"><IMG WIDTH=26 HEIGHT=24 ALIGN=BOTTOM ALT="up" SRC="../icons/up_motif.gif"></A> <A NAME="tex2html5099" HREF="page339.html"><IMG WIDTH=63 HEIGHT=24 ALIGN=BOTTOM ALT="previous" SRC="../icons/previous_motif.gif"></A>  <A NAME="tex2html5109" HREF="page611.html"><IMG WIDTH=43 HEIGHT=24 ALIGN=BOTTOM ALT="index" SRC="../icons/index_motif.gif"></A> <BR><HR><H1><A NAME="SECTION0010700000000000000000">B-Trees</A></H1><P>Just as AVL trees are balanced binary search trees,<em>B-trees</em><A NAME=20983>&#160;</A>are balanced <I>M</I>-way search trees.<A NAME="tex2html587" HREF="footnode.html#21047"><IMG  ALIGN=BOTTOM ALT="gif" SRC="../icons/foot_motif.gif"></A>By imposing a <em>balance condition</em><A NAME=20989>&#160;</A>,the shape of an AVL tree is constrained in a way which guarantees that the search, insertion, and withdrawal operations are all  <IMG WIDTH=56 HEIGHT=24 ALIGN=MIDDLE ALT="tex2html_wrap_inline59347" SRC="img400.gif"  >,where <I>n</I> is the number of items in the tree.The shapes of B-Trees are constrained for the same reasonsand with the same effect.<P><BLOCKQUOTE> <b>Definition (B-Tree)</b><A NAME="defnbtree">&#160;</A>A <em>B-Tree of order <I>M</I></em><A NAME=20994>&#160;</A>is either the empty treeor it is an <I>M</I>-way search tree <I>T</I> with the following properties:<OL><LI> The root of <I>T</I> has at least two subtrees and at most <I>M</I> subtrees.<LI> All internal nodes of <I>T</I> (other than its root)	have between  <IMG WIDTH=41 HEIGHT=24 ALIGN=MIDDLE ALT="tex2html_wrap_inline64977" SRC="img1328.gif"  > and <I>M</I> subtrees.<LI> All external nodes of <I>T</I> are at the same level.</OL></BLOCKQUOTE><P>A B-tree of order one is clearly impossible.Hence, B-trees of order <I>M</I> are really only defined for  <IMG WIDTH=45 HEIGHT=24 ALIGN=MIDDLE ALT="tex2html_wrap_inline64641" SRC="img1293.gif"  >.However, in practice we expect that <I>M</I> is largefor the same reasons that motivate <I>M</I>-way search trees--large databases in secondary storage.<P>Figure&nbsp;<A HREF="page340.html#figbtree1"><IMG  ALIGN=BOTTOM ALT="gif" SRC="../icons/cross_ref_motif.gif"></A> gives an example of a B-tree of order <I>M</I>=3.By Definition&nbsp;<A HREF="page340.html#defnbtree"><IMG  ALIGN=BOTTOM ALT="gif" SRC="../icons/cross_ref_motif.gif"></A>,the root of a B-tree of order three has either two or three subtreesand the internal nodes also have either two or three subtrees.Furthermore, all the external nodes,which are shown as small boxes in Figure&nbsp;<A HREF="page340.html#figbtree1"><IMG  ALIGN=BOTTOM ALT="gif" SRC="../icons/cross_ref_motif.gif"></A>,are at the same level.<P><P><A NAME="21232">&#160;</A><A NAME="figbtree1">&#160;</A> <IMG WIDTH=575 HEIGHT=213 ALIGN=BOTTOM ALT="figure21001" SRC="img1329.gif"  ><BR><STRONG>Figure:</STRONG> A B-tree of order 3.<BR><P><P>It turns out that the balance conditions imposed by Definition&nbsp;<A HREF="page340.html#defnbtree"><IMG  ALIGN=BOTTOM ALT="gif" SRC="../icons/cross_ref_motif.gif"></A>are good in the same sense as the AVL balance conditions.That is, the balance condition guarantees that the height of B-treesis logarithmic in the number of keys in the treeand the time required for insertion and deletion operations remains proportional to the height of the treeeven when balancing is required.<P><BLOCKQUOTE> <b>Theorem</b><A NAME="theoremsrchtreeiii">&#160;</A>The minimum number of keysin a B-tree of order  <IMG WIDTH=45 HEIGHT=24 ALIGN=MIDDLE ALT="tex2html_wrap_inline64641" SRC="img1293.gif"  > and height  <IMG WIDTH=37 HEIGHT=24 ALIGN=MIDDLE ALT="tex2html_wrap_inline63063" SRC="img1074.gif"  > is <IMG WIDTH=128 HEIGHT=28 ALIGN=MIDDLE ALT="tex2html_wrap_inline64997" SRC="img1330.gif"  >.</BLOCKQUOTE><P>	extbfProofClearly, a B-tree of height zero contains at least one node.Consider a B-tree order <I>M</I> and height <I>h</I><I>&gt;</I>0.By Definition&nbsp;<A HREF="page340.html#defnbtree"><IMG  ALIGN=BOTTOM ALT="gif" SRC="../icons/cross_ref_motif.gif"></A>,each internal node (except the root) has at least  <IMG WIDTH=41 HEIGHT=24 ALIGN=MIDDLE ALT="tex2html_wrap_inline64977" SRC="img1328.gif"  > subtrees.This implies the minimum number of keys contained in an internal nodeis  <IMG WIDTH=71 HEIGHT=24 ALIGN=MIDDLE ALT="tex2html_wrap_inline65005" SRC="img1331.gif"  >.The minimum number of keys a level zero is 1;at level one,  <IMG WIDTH=92 HEIGHT=24 ALIGN=MIDDLE ALT="tex2html_wrap_inline65009" SRC="img1332.gif"  >;at level two,  <IMG WIDTH=139 HEIGHT=24 ALIGN=MIDDLE ALT="tex2html_wrap_inline65011" SRC="img1333.gif"  >;at level three,  <IMG WIDTH=145 HEIGHT=28 ALIGN=MIDDLE ALT="tex2html_wrap_inline65013" SRC="img1334.gif"  >; and so on.<P>Therefore the minimum number of keys in a B-tree of height <I>h</I><I>&gt;</I>0 is givenby the summation<P> <IMG WIDTH=500 HEIGHT=119 ALIGN=BOTTOM ALT="eqnarray21242" SRC="img1335.gif"  ><P><P>A corollary of Theorem&nbsp;<A HREF="page340.html#theoremsrchtreeiii"><IMG  ALIGN=BOTTOM ALT="gif" SRC="../icons/cross_ref_motif.gif"></A> is that the height, <I>h</I>,of a B-tree containing <I>n</I> keys is given by<P> <IMG WIDTH=334 HEIGHT=19 ALIGN=BOTTOM ALT="displaymath64955" SRC="img1336.gif"  ><P><P>Thus, we have shown that a B-tree satisfiesthe first criterion of a good balance condition--the height of B-tree with <I>n</I> internal nodes is  <IMG WIDTH=56 HEIGHT=24 ALIGN=MIDDLE ALT="tex2html_wrap_inline59347" SRC="img400.gif"  >.What remains to be shown is that the balance condition can beefficiently maintained during insertion and withdrawal operations.To see that it can,we need to look at an implementation.<P><BR> <HR><UL> <LI> <A NAME="tex2html5110" HREF="page341.html#SECTION0010710000000000000000">Implementing B-Trees</A><LI> <A NAME="tex2html5111" HREF="page344.html#SECTION0010720000000000000000">Inserting Items into a B-Tree</A><LI> <A NAME="tex2html5112" HREF="page347.html#SECTION0010730000000000000000">Removing Items from a B-Tree</A></UL><HR><A NAME="tex2html5107" HREF="page341.html"><IMG WIDTH=37 HEIGHT=24 ALIGN=BOTTOM ALT="next" SRC="../icons/next_motif.gif"></A> <A NAME="tex2html5105" HREF="page298.html"><IMG WIDTH=26 HEIGHT=24 ALIGN=BOTTOM ALT="up" SRC="../icons/up_motif.gif"></A> <A NAME="tex2html5099" HREF="page339.html"><IMG WIDTH=63 HEIGHT=24 ALIGN=BOTTOM ALT="previous" SRC="../icons/previous_motif.gif"></A>  <A NAME="tex2html5109" 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 + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -