B-T Inverters : Bayer ' ? McCreight , 1970 Boeing Research Labs . - - - PowerPoint PPT Presentation
B-T Inverters : Bayer ' ? McCreight , 1970 Boeing Research Labs . - - - PowerPoint PPT Presentation
B-T Inverters : Bayer ' ? McCreight , 1970 Boeing Research Labs . - tree ? why B- ? ? Bayer , Boeing , Broad , Bushy , . . . . . . . the more you think about what " McCreight , 2014 means , the better you understand the Bin B- trees B-
Inverters : Bayer
'? McCreight ,
1970
Boeing Research Labs.
why B-
- tree ?
Bayer , Boeing , Broad , Bushy ,
. . . .? ?
McCreight , 2014
"
. . . the more you think about whatthe Bin B-trees
means , the better you understand
B- trees .
"(The paper introducing them
was initially rejected)
m-arysearchtree.sn
rooted trees where
- each node may have up to m children
- a node with
K children has k-1 keys
- search is
a natural generalization of BSTsearch :
' Exi An order - 5 ( 5- ar y) search tree .search for8\h
A
⇐
727
262
779
<27, 62
179
L 97
- Search is a generalization of BST search
- Generalization of in - order traversal visits keys in order
- I
Order m B-Tree ( As per textbook)
5-
*
" m- artree ,
- data Items stored at
leaves , keys in other nudes guide search
- non- leaf nodes , other thanthe root have
between TM1N and
m children
- the root has between 2 and
M children , or
is a leaf
- in a
non - heat
node , the
ith key
is the smallest
key stored in the Itt" subtree
- all leaves
are at the
same depth
. leaves contain between Mil andL keys ( for
some
(unless there
are fewer than THE
L
fixed L )
.keys
in the
tree
. ) .* in this version of B-tree , not an
m -ary search tree asdefined on
previous
slide .
B-Tree Search : Generalization of BST search .
- Example , in an order -5 B-tree
:(
This tree :
- must
have
- rder 75 because of
*
- must
not
be of order 56
because of D.)
Find 49:\
µ
⑤
③
"
3
sieetetteightofttperfecttrees-Aperfeetm-arytree-isanm.ae
ry tree where :
- every node has Zero
- r
m children
- every
leaf has the same
depth
- A perfect m-ary tree of height h has the max # of
nodes for
a height
- h m-ary tree
Fact:
The number of nodes in a perfect
m - airy tree of
- height h
is :
mh
m - I
for : The number of nodes in
a perfect binary tree
- f height
h
is
2h11
.The number of nodes at depth d. in a perfect
'binary tree
- f height at
least d
is
2d
- Proof By induction
- n d
Basis : D= 0
.2d -20=1
- I. It . Choose
some d
' 70an assume that
the number of
nodes at depth d
is 2d
Is . We must show that the number of
nodes
- at depth
dH
is 2d?
✓↳ since the tree
is
a perfect binary tree
&
- f height
> dtl , every node at
:
depth
d
has
2 children .
d-
a- /\o
So
, the number ofnodes at depth dtt
dtt
is g. 2d
= 2dt¥The number of
nodes at depth d
in a perfect m - ary
tree of height at
least d
is md
.PI By induction
- n depth d-
Basis:
D= 0
.There
is just the root
, and md=m° = IIII.
:Choose
some d > 0
and
assume the
number of nodes at depth d
is
md
.II.
: We must show that the number of nodes atdepth dtl
is mdtt
.Since the tree is
a perfect m - ary tree of
height
at
least dtt
,every
node at
depth d has
m children .
So
, the number ofnodes at depth dtl
is
M
- Md
Claim : Every
- rder
- m B-tree of height h
contains
at
least (E)
h
keys
.P¥ Observe that every m- ary B-tree of height
h
has a perfect (f)
- cry tree as
a
sub
- graph
:
⇒
This
"subtree " has (E)"
leaves
,so the B-tree
does also
.Since each leaf
has at least hz keys ,
the B- tree
contains at least CH2Xmath key
5.1¥ : The height of
an order - m
B-tree with
n
keys
is
at most
log m=n
= 0( log n)If :
Let T be an order m B-tree with
n nodes
- and height h .
We have : ¥)h
±
n
So
h
E
log; n =0(log
n)
⇐ Searching for
a key in a B-tree with
n keys
can be done in time 0( log
n ) .B-treeinserti.org/L=m-- 5)
① Insert 577
¥
*
After inserting 57 :
go
.
Now , insert 5
[
This leaf will be "overfull"
=D we spH
÷:÷÷÷:¥i⇒
.After insertion of 554 splitting of leaf :
splittinganInternalhlodet-ns.at
407
←
.* splitting the leaf
g④F%¥¥
" ¥
¥
:
Afterspliking
splittingtheRoot.orerfullroyt.j.IT/.y?Newroot
.11111×117 EE
THI THI
A
1 b. b. x.
.
.
I b. b. ¥
, I k
Tree just got taller
. Still , leaves allhave the
same (larger) depth
.BTreeInsertij
Find the leaf where
new key k belongs , call it
v.
a insert K intov
while(v
is
- ver- full and not the root
) {
isplit
v.
v ← parent G)
¥ r
is the
root and
- ver - full
v
in two ,
. adda
new root with two children
- Claim : B - tree
insertion can be done
in
time
0 ( log n) , where
n is the number of
keys
in the tree
.B-treeRemov
. Find the leafL with the key K
to be removed
- delete K from L
- if
K was the smallest key in L , correct the key in an ancestor
- V ← L
- ( r
has too few keys
and
is not root) {
if ( v has an adjacent sibling u with more than MK7 children)l
shift
a key and child from it to v.
} else{
merge
v with a sibling
- f r
}
u ← parent of the merged
node
}
if I v
is root and has only
- ne child , c )
delete vj
c is the
new root .
(corrected.)
Ifkwasthesmadestheafinl.ir
①
,
⇒
'
If node v has too few keys
and
is
not root . .
.- sometimes
can metre
v with
an adjacent sibling
1-
i¥¥⇒
'¥R
- ADD A
n
A
A
A
D B
- sometimes not
1-
merging
r with a
H¥
✓ I
1
I \
sibling makes
5¥ D; f I
a node
that is Overfull
fEff⇒)
I'T
remove 79
=D
→
in :
¥
it.sn.
y
"extra " means/
④ shift
a key (76)
more than the
.+
min
.T
Et
t t
↳
:( corrected)
tIingunderfuHnod
:- shifting
is cheaper than
merging ,
and never leaves the
parent under -full
⇐ ⑤ ' . . fix by shifting ifpossible
. ifnot possible
( both adjacent siblings
have
min . # keys)
,then fix by
merging
.tixinfuging.GL?fym=5)
12614116¥
remove
52
←
←
to
→
I
TITHE
HH
am
I
p
b
t
b I
*
I too small
merge with sibling
¢
d-
*
→
m
%
shiftingataninternaluodlnas.IE
:b
"
to 1 ↳ ←
too few
.A T¥
shift a key+ child.
→
¥71
µ. aissi rotation)
4 I
✓
↳
e
Hn
*
i.
*
1¥
tool
*
whenamergeshrinksaninterndnode-T.IE
← ↳ I
← just
got
too
small
ADD A
A
because of a
T1
The
T3
T4 T5
deletion
$
merge
Y
9-
I
/
I
1
I
l
A DAD D
TI
T2
T3 T4
T5
whentherootgetstoosmali.FI
← ↳
T
Fol ← just
got
too
small
/
I1
IT
.17PM
17 17
$
merge
IBE
Tree height
④so¥
is
reduced
/
I
1
'
'
by
1
.LOmparisonof2logznandlogmk.lv
- rst case height of Avhtree
- We choose
m= 1024 , for a concrete
example
.R
Rogen Logan
- 10
7
I
100
13 I
1000
20 I 104
27
2
106
40
2
108
53
3
10"
66
4
10 " 80 5
(logout
= logz×%gz5k = 108249 = 2logixfg)End
Motivation