search for 8\h is 779 262 727 L 97 < 27 179 , 62 - Search is - - PowerPoint PPT Presentation

search for 8 h
SMART_READER_LITE
LIVE PREVIEW

search for 8\h is 779 262 727 L 97 < 27 179 , 62 - Search is - - PowerPoint PPT Presentation

m-arysearchtree.sn rooted trees where each node may have up to m children K children has k -1 keys . a node with a natural generalization of BST search : search is ' Exi An order - 5 ( 5- ar y ) search tree . search for 8\h is


slide-1
SLIDE 1

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

is

727

262

779

<27

, 62

179

L 97

  • Search is a generalization of BST search
  • Generalization of in - order traversal visits keys in order
.
slide-2
SLIDE 2

Order m B-Tree ( As per textbook)

5.

m- ar

search tree

  • data Items stored at

leaves , keys in other nodes 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 ittst subtree

. all leaves

are at the

same depth

. leaves contain between Mil and

L keys ( for

some

(unless there

are fewer than Hd

(

fixed L )

.

keys

in the

tree

. ) .
slide-3
SLIDE 3

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

> 6 because of D.)

Find 49:\

⑤ ¥

"

3

slide-4
SLIDE 4

sieetetteight.fi/Perfect''Trees-Aperfeetm-arytree-

is

an

m - ary 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-5
SLIDE 5

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

  • 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

dtt

is 2d?

Since the tree

is

a perfect binary tree

  • f height

> dtl , every node at

depth

d

has

2 children .

So

, the number of

nodes at depth dH

is 2. 2d

= 2
slide-6
SLIDE 6

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

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

:

n

'

This subtree has (E)

"

leaves

,

so the B-tree

does also

.

Since each leaf

has at least

HE keys , the B- tree contains at least CH2Xmath key

5.
slide-8
SLIDE 8

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-9
SLIDE 9

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

① Insert 577

I

*

slide-10
SLIDE 10

After inserting 57 :

go

.

Now , insert 5

[

This leaf will be "overfull"

=D we spH

÷

'
slide-11
SLIDE 11

After insertion of 554 splitting of leaf :

slide-12
SLIDE 12

splittinganInternalhlodet-ns.at

407

.

* splitting the leaf

g④F%¥¥

¥**¥t¥:¥I¥÷¥

slide-13
SLIDE 13

Aftersplikinj

slide-14
SLIDE 14

sphttingtheRoot.orerfullroyt.j.IT/.y?Newroot

.

11111114k¥

THI

TI

Ab

Abb

bbb 'd

1

2

3

4

5

6

1

2

3

4

5

6

Tree just got taller

  • Still , leaves all

have the

same (larger) depth

.
slide-15
SLIDE 15

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 ,

i 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-16
SLIDE 16 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 with more than

FY27 children)l

shift

a key and child

  • rom th
  • or

I

} else{

merge

v with a sibling

  • f r

g

v ← parent of the merged

node

}

if I v

is root and has only

  • ne child , c )

delete vj

c is the

new root .

slide-17
SLIDE 17

5*1

(0Iff=5)

↳ IT

5k¥

THEE

:*

:*

delete 52

¥

*

delete 78

19

µss¥*H

hI¥e#

* tbh

It

by ↳

¥

:

A

too small

keys

.

4 too

small

Hr merge with sibling

④ shift

a key

d-

.

µ and

child

.

$1

1-

Ff¥¥

Is

%

F¥F⇒

slide-18
SLIDE 18

shiftingataninternaluodl.ua

III

'm

.

& I ↳ ←

too few

.

A TIE

shift a keyt child.

It

e

Hn

*

i.

*

¥4

tool

slide-19
SLIDE 19

whenamergeshrinksaninternalnode-T.IE

← ↳

Fol ← just

got

too

small

/

I

1

IT

because of a

17 PM

D D

deletion

$

merge

Y

9-

I

/

I

1

I

l

slide-20
SLIDE 20

whentherootgetstoosmall.LI

← ↳

Fol ← just

got

too

small

/

I

1

IT

.

17 PM

17 17

$

merge

to

I

/

1

I

1

I