80 likes | 226 Views
Árvore B. Algoritmo de Inserção. Raghu Ramakrishman (by Gustavo Tadao). Lista de valores. Root. 7. 1. 10. 20. 30. 40. 2. Folhas. 1. 3. 8. 9. 13. 15. 17. 191. 21. 24. 25. 28. 32. 35. 37. 39. 40. 43. 46. 47. 1. 3. 7. 8. 9.
E N D
Árvore B Algoritmo de Inserção Raghu Ramakrishman (by Gustavo Tadao)
Lista de valores Root 7 1 10 20 30 40 2 Folhas 1 3 8 9 13 15 17 191 21 24 25 28 32 35 37 39 40 43 46 47 1 3 7 8 9 Newchildentry = &<7> Split L (is leaf) Set sibling poiters in L and L2 Insert(Pi, 7, newchildentry<NULL>) Find i such that Ki <= entry’s keyvalue < Ki+1 (is non-leaf) Insert(root, 7, newchildentry) (has no space) Return (newchildentry = &<7>) Próxima Página
Root 20 Root 10 20 30 40 7 10 20 30 40 30 40 1 3 7 8 9 13 15 17 19 21 24 25 28 32 35 37 39 40 43 46 47 N is root Create new node with (pointer to N, <20>) Split N (has no space) Make the tree’s root-node pointer to the new node; return Newchildentry = &<20> Fim
Algoritmo de Remoção Raghu Ramakrishman
Lista de valores 19 17 24 5 13 27 30 2 3 5 7 8 14 16 22 19 24 24 24 27 29 33 34 38 39 Return Delete(nodepointer, Pi,entry, oldchildentry) Remove entry (is non-leaf) Find i such that Ki <= entry’s keyvalue < Ki+1 Find i such that Ki <= entry’s keyvalue < Ki+1 (is non-leaf) Delete(nodepointer, Pi,entry, oldchildentry) Has entries to spare Delete(parentpointer<NULL>,Pi,19, oldchildentry<NULL>) (Is leaf)
Lista de valores 19 17 24 5 13 27 30 2 3 5 7 8 14 16 22 24 27 29 33 34 38 39 Delete(nodepointer, Pi,entry, oldchildentry) Doesn’t have entries to spare – Merge L and S (is non-leaf) Find i such that Ki <= entry’s keyvalue < Ki+1 Delete(nodepointer, Pi,entry, oldchildentry) (is non-leaf) Find i such that Ki <= entry’s keyvalue < Ki+1 (Is leaf) Delete(parentpointer<NULL>,Pi,24, oldchildentry<NULL>) Oldchildentry = &<27> Próximo
Lista de valores 19 17 24 New Root 5 13 17 30 27 30 30 2 3 5 7 8 14 16 22 27 29 27 29 33 34 38 39 Move all entries from M to node on left Return Remove *Oldchildentry from N Doesn’t have entries to spare – Merge N and S Pull spliting key from parent down into node on left Move all entries from M to node on left Return Fim