Você está na página 1de 10

Banco de Dados

Indexao

ltima atualizao: 20 de janeiro de 2006

Prof. Joao Eduardo Ferreira Prof. Osvaldo Kotaro Takai

Introduo
Este material apresenta uma simulao dos algoritmos de insero e remoo de rvore B proposto por Raghu Ramakrishman. Detalhes do algoritmo podem ser encontrados em:
Database Management System pg.: 256 264, para detalhes vide bibliografia.

http://www.ime.usp.br/~jef/Btree.pdf

Algoritmo de Insero
Raghu Ramakrishman
Database Management System pg.: 256 - 264

Lista de valores

Root

7
1

10

20

30

40

Folhas

1 3 8 9

13 15 17191

21 24 25 28

32 35 37 39

41 43 46 47

1 3

7 8 9

Find i such Newchildentry in &<7> L2 < Ki+1 Insert(Pi, (newchildentrykeyvalue Return 7,(is<= entrys L= &<7>) Set that(hasSplit L = and Insert(root,poiters sibling (is leaf) Ki non-leaf) newchildentry<NULL>) 7, newchildentry) no space)

Prxima Pgina

Root

20
Root

10 7

20 10

30

40

20 30

30 40

40

1 3

7 8 9

13 15 17 19

21 24 25 28

32 35 37 39

41 43 46 47

Make the trees root-noderoot &<20> N, new node; Create new nodeNreturn = Newchildentry (hasSplitspace) to the <20>) with pointer to no (pointer is N

Fim

Algoritmo de Remoo
Raghu Ramakrishman

Lista de valores

19 24

17

13

27

30

14 16

22 19 24 24

27 29

33 34 38 39

Delete(parentpointer<NULL>,Pi,19,keyvalue < Ki+1 Find i such that Remove to spare Delete(nodepointer, Pi,entry,oldchildentry<NULL>) Has (is<= entrys oldchildentry) Ki (Is leaf) entries entry Return non-leaf)

Lista de valores

19 24

17

13

27

30

14 16

22 24

27 29

33 34 38 39

Delete(parentpointer<NULL>,Pi,24,keyvalue L and S Doesnt have entriesnon-leaf) oldchildentry) Find i such Oldchildentry = &<27> Delete(nodepointer, Pi,entry,oldchildentry<NULL>) that Ki <= entrys Merge < Ki+1 (is(Is leaf) to spare

Prximo

Lista de valores

19 24

17

New Root

13

17

30

27 30

30

14 16

22 27 29

27 29

33 34 38 39

Pull spliting keyentriesReturndownMerge N and S Doesnt Remove *Oldchildentrynode on lefton left Move all entries from M to from node have from parent to spare into N Fim

Bibliografia
Korth, H.; Silberschatz, A. Sistemas de Bancos de Dados. 3a. Edio, Makron Books, 1998. Ramakrishnan, R.; Gehrke, J., Database Management Systems, 2 nd ed., McGraw-Hill, 2000.

Você também pode gostar