B-T Inverters : Bayer ' ? McCreight , 1970 Boeing Research Labs . - - - PowerPoint PPT Presentation

b t
SMART_READER_LITE
LIVE PREVIEW

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-


slide-1
SLIDE 1

B-T

slide-2
SLIDE 2

Inverters : Bayer

'

? McCreight ,

1970

Boeing Research Labs.

why B-

  • tree ?

Bayer , Boeing , Broad , Bushy ,

. . . .

? ?

McCreight , 2014

"

. . . the more you think about what

the Bin B-trees

means , the better you understand

B- trees .

"

(The paper introducing them

was initially rejected)

slide-3
SLIDE 3

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
slide-4
SLIDE 4

Order m B-Tree ( As per textbook)

5-

*

" m- ar

tree ,

  • 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 and

L 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 as

defined on

previous

slide .

slide-5
SLIDE 5
slide-6
SLIDE 6

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

slide-7
SLIDE 7

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

.
slide-8
SLIDE 8

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

' 70

an 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 of

nodes at depth dtt

dtt

is g. 2d

= 2dt¥
slide-9
SLIDE 9

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° = I

III.

:

Choose

some d > 0

and

assume the

number of nodes at depth d

is

md

.

II.

: We must show that the number of nodes at

depth 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 of

nodes at depth dtl

is

M

  • Md
= mdtlµ
slide-10
SLIDE 10

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.
slide-11
SLIDE 11

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 ) .
slide-12
SLIDE 12

B-treeinserti.org/L=m-- 5)

① Insert 577

¥

*

slide-13
SLIDE 13

After inserting 57 :

go

.

Now , insert 5

[

This leaf will be "overfull"

=D we spH

÷:÷÷÷:¥i⇒

.
slide-14
SLIDE 14

After insertion of 554 splitting of leaf :

slide-15
SLIDE 15

splittinganInternalhlodet-ns.at

407

.

* splitting the leaf

g④F%¥¥

" ¥

¥

:

slide-16
SLIDE 16

Afterspliking

slide-17
SLIDE 17

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 all

have the

same (larger) depth

.
slide-18
SLIDE 18

BTreeInsertij

Find the leaf where

new key k belongs , call it

v.

a insert K into

v

while(v

is

  • ver- full and not the root

) {

i

split

v.

v ← parent G)

¥ r

is the

root and

  • ver - full
. split

v

in two ,

. add

a

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

.
slide-19
SLIDE 19 I

B-treeRemov

. Find the leaf

L 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
= while
  • ( 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.)

slide-20
SLIDE 20

Ifkwasthesmadestheafinl.ir

,

'

slide-21
SLIDE 21

If node v has too few keys

and

is

not root . .

.
  • sometimes
, we

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

✓ I

1

I \

sibling makes

5¥ D; f I

a node

that is Overfull

slide-22
SLIDE 22

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)

slide-23
SLIDE 23

tIingunderfuHnod

:
  • shifting

is cheaper than

merging ,

and never leaves the

parent under -full

⇐ ⑤ ' . . fix by shifting if

possible

. if

not possible

( both adjacent siblings

have

min . # keys)

,

then fix by

merging

.
slide-24
SLIDE 24

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

%

slide-25
SLIDE 25

shiftingataninternaluodlnas.IE

:b

"

to 1 ↳ ←

too few

.

A T¥

shift a key+ child.

¥71

µ. aissi rotation)

4 I

e

Hn

*

i.

*

tool

*

slide-26
SLIDE 26

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

slide-27
SLIDE 27

whentherootgetstoosmali.FI

← ↳

T

Fol ← just

got

too

small

/

I

1

IT

.

17PM

17 17

$

merge

IBE

Tree height

④so¥

is

reduced

/

I

1

'

'

by

1

.
slide-28
SLIDE 28

LOmparisonof2logznandlogmk.lv

  • rst case height of Avhtree
us B-Tree .
  • 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)
slide-29
SLIDE 29

End

slide-30
SLIDE 30

Motivation