BTree - PowerPoint PPT Presentation

1 / 10
About This Presentation
Title:

BTree

Description:

?? ?????????? ?????? ????? ????? ??????? (???? ????? ???????) ... 8 B-Tree-Slit-Child(s,1,r) 9 B-Tree-Insert-Nonfull(s,k) 10 else B-Tree-Insert-Nonfull(r,k) ... – PowerPoint PPT presentation

Number of Views:42
Avg rating:3.0/5.0
Slides: 11
Provided by: mao5
Category:
Tags: btree | slit

less

Transcript and Presenter's Notes

Title: BTree


1
B-Tree
  • ?? ????? ????? .
  • ????? ???? ????? ?? ?????? ??? ????? ?? ???? ????
    ????? ??? ????? ???????.
  • ?????? ????? ???? ????? ???? ?? ?? ????? ???????.
  • ???? ???? ???? ???? ?? ????? ???? ???????.
  • ?? ?????????? ?????? ????? ????? ??????? (????
    ????? ???????)
  • ???? ???? ???? ??? ?????? ??????? ?? ???????????
    ?????? ??????? ?????
  • ??? ???? ??????. ?????? ????? ???? ????
    ?????? ???????.
  • ?????? ?? ?? B-Tree
  • ???? ?? ?????? x ???? ?????? ??????? nx ,
    ?????? ??????? ???? ????? , ??? leafx - true
    ?? ???
  • ?? ?????? ???? nx 1 ???? .
  • ?? ????? ????? ????
  • ?????? ??? ?????? ?? 2t 1 ??????
  • ?? ??? ???????? ????????? ????? ?????? ??????? .
    ????? ?"? t .
  • ??? ?????? ?? ??? ????? t 1 ?????? ???? ?????
    2t 1 ??????
  • ??? ?????? ?? ??? ????? t ???? ???? ????? 2t
    ????
  • ?????? ??? ?????? ?? 2t1 ??????
  • ??? ????? ????? ??? ?? ?? t2 ???? ??? ??????
    ????? ?? 2 , 3 ?? 4 ????. ???? ??? ??????? ?- t
    ???? ???? .

2
???? ???
  • ????
  • ??? ngt1. ???? ?? ?? n ?????? ?????? h ??????
    ????????? 2t ???? hltlogt( (n1)/2 )
  • ?????
  • ??? ????? h ?? ???? ?????? ?????????? ???? ?????
    ??? ?? ???? 1 ???? ?????? ????? ?? t-1 ??????
  • ????? 1 ??? ?? 2 ???????
  • ????? 2 ??? ?? 2t ???????
  • ????? 3 ??? ?? 2t2???????
  • ????? h ?? 2th-1 ???????
  • ????? ???? h3 ???? n ????? ?? ???? ???????
    ????? .
  • n gt 1 (t-1) ? 2ti-1 1 2(t-1)( (th
    1)/(t-1) ) 2th - 1
  • i 1 to h
  • ???? ????? ??? ???????? ????? ?? t ( t ???? ) .
  • ??? B-Tree ?????? ????? ?? ???? ???? ?????? ????
    ??????? ????? . ??????? ?????? ?? log(t)

3
?????? ???
  • ????? ???? ??? ???? ??????? (??????? ?????
    ???? ????? ???? ?????)
  • ?? ?????? ????? ??????
  • ?????
  • ??? ????? ??? ?????? ?? ????? ??????? ?? ???
    ??? ???? ????? ??????? ???????.
  • ???? ?????? ????? x ?????? nx ?????? ????
    ?????????.
  • ??? ?????? x ????? k
  • ????? ??????? ?? B-Tree-Search(root(T),
    k) ????? (y,i) ??? k ???? ????? null
  • ?????? cix ??? ?- i ?? x
  • nx ???? ??????? ???????
    ?- x
  • keyix ????? ?- i ??????? x

4
???????? ??????
  • B-Tree-Search(x,k)
  • 1 i 1
  • 2-3 while ( iltnx and kgtkeyix ) do
    i i1
  • 4-5 if ( iltnx and kkeyix )
    then return(x,i)
  • 6-7 if ( leafx )
    then return(null)
  • 8
    else DiskRead(cix)
  • 9
    return(
    B-Tree-Search(cix,k) )
  • ????? 1-3 ????? ???? ??????? ??????? i ???
    ????? ?? ??????? kltkeyix ?? ?- inx1
  • ????? 4-5 ?????? ?? ???? ????? ?????? ??? ??
    ??????? ????
  • ????? 6-9 ?? ???? ??? ????? ?? ???? k ??????
    null
  • ?? ?? ??? ?????? ????? ????????? ?? ?? ???
    ??????
  • ?????? ?????? ?(logt(n)) ?(h) ???? ???? ???
    ??? h , n ???? ??????? ???.
  • ?????? cpu ??? ?? ?- nxlt2t ???? ????
    ??????? ?????? 2 ?-3 ??? O(t)
  • ??? ????? ?-cpu O(tlogt(n)) O(th)

5
????? ?? B-Tree
  • ????? ????? ???? ??? ????? ????? ?? ???? ??? ???
  • ???????? Allocate-Node() ????? ?????? ??? ?????
    ?? ?? ?????. ??? ????? ???????? O(1) .
  • B-Tree-Create(T)
  • 1 x Allocate-Node()
  • 2 leafx true
  • 3 nx 0
  • 4 DiskWrite(x)
  • 5 rootT x
  • ??? ????? cpu O(1)
  • ??? ???? O(1) ?? ????? ????? ???
    ?????

6
????? ??????
  • ????? ???? ???? ????? ???? ???????.
  • ?????? ????? ???? ??????? ??? (?? 2t-1 ??????)
  • ?????? ??? ??????? ??? t-1 ?????? ?? ???. ?????
    ?????? ???? ??? ?? ??????? ?????? ???? ??? ?? ???
  • ?? ??? ?? ??????? ??? ???? ??? ??? ????
  • ????????? B-Tree-Split-Child
  • ??? ?????? ????? x ?? ???
  • ?????? i
  • ?????? y ?? ?- ycix ????? ????? ???
  • gt ????? ????? ???? ?? x ??- x ???? ???
  • y ???? ?-i ?? x ???? 2t-1 ??????
  • z ?????? ??? ????? ?? t-1 ??????? ???????
    ??????? ?- y ?????? ??? ?? x ????? ???? ?- y .
  • ????? ?- t (??????) ??????? y ????? ??????? x
    ???? ????? ??? ??? y ???? ??? z

7
???????? ?????? B-Tree-Split-Child
  • ????? 1-8 ????? ?????? z ?????? ???????
    ????
  • ???? 9 ????? ???? ??????? ?-y
  • ????? 10-16 ??????? ?? z ??? ?? x
  • ????? ????? ?????? ?? y ?- x
  • ????? ???? ??????? ?- x
  • ????? 17-19 ????? ?? ???????? ?????
  • ??? cpu ?(t) ??? ??????? ?????? 4-5 ???????
    7-8
  • ????? ?????????
  • B-Tree-Split-Childe(x , I , y)

8
????? ????
  • B-Tree-Insert(T,k)
  • 1 r rootT
  • 2-3 if ( nr 2t-1 ) then s
    Allocate-Node()
  • 4
    rootT s
  • 5
    leafS false
  • 6 ns
    0
  • 7
    c1s r
  • 8
    B-Tree-Slit-Child(s,1,r)
  • 9
    B-Tree-Insert-Nonfull(s,k)
  • 10 else
    B-Tree-Insert-Nonfull(r,k)
  • ????? 3-9 ?? ???? ??? ??? ????? ????? ?????
    ??????? ??? s ???? ????? ?????.
  • ????? ????? ?? ???? ????? ?????? ???? ???
  • ????? ???? k ??? ??????? ?? ??? ?????? ??
    ????? ????????? B-Tree-Insert-Nonfull
  • ????????? B-Tree-Insert-Nonfull ????? ?????????
    ???? ??? .
  • ?????? ???? O(h) ?? ???? ??? ????? ??? ???
    ???
  • ?????? cpu O(tlogt(n)) O(th)
  • ????????? B-Tree-Insert ?????? ?????????
    B-Tree-Split-Child ??? ?????? ??????? ??????????
    ?????????
  • B-Tree-Insert ???? ????? ?? ?????? ????
    ?? ???.

9
????? ???? ????
B-Tree-Insert-Nonfull(x,k) 1 i
nx 2-3 if ( leafx ) then while ( igt1
and kltkeyix ) 4
do keyi1x keyix 5
i
i1 6
keyi1x k 7
nx nx 1 8
DiskWrite(x) 9-10
else While ( igt1 and kltkeyix ) do
i i-1 11
i i 1 12
DiskRead(cix) 13
if ( ncix 2t-1 ) 14
then B-Tree-Split-Child
(x,i,cix) 15-16
if ( kgtkeyix) then i i1 17

B-Tree-Insert-Nonfull(cix,k)

10
B-Tree-Insert-Nonfull(x,k) ????
  • ????? 3-8 ???? x ??? ?????? k ?- x
  • ????? 9-11 ?? x ?? ??? ????? ?? k ????
    ?????? ??? ??? ?????? ?- x
  • ???? 13 ?? ????? ??????? ??? ?? ?? ??
    ?? ????? ????? 14 ???? ????? 15
  • ???? 14 ???? ?????? ??? ????? ????? ??
    ???????
  • ????? 15-16 ????? ???? ?? ??????? ????? ???
    ?????? ????
  • ????? 13-16 ??????? ??? ?????
    ????????? ?? ?????? ???
  • ???? 17 ????? ???? k ?????
  • ?????? ???? ???????? ?"? B-Tree-Insert ???
    O(h) ???? ?? ????? h
  • ?? ?? ????? ????? ??? ???? ?????? ?-
    B-Tree-Insert-Nonfull ?? ????? ??? ????
  • ??? cpu O( tlogt(n) ) O(th) ??
    ??????? B-Tree-Insert-Nonfull ??? ??????? ???
    ???? ???? ???????
  • ?????? while.
Write a Comment
User Comments (0)
About PowerShow.com