This preview shows pages 1–3. Sign up to view the full content.
This preview has intentionally blurred sections. Sign up to view the full version.View Full Document
Unformatted text preview: 11-7 NotesAlgorithms and Data Structures•Every node of a B-tree must contain at least t-1 keys and at most 2t-1 keys (except root may have as few as one key)M/ \DH QTX/ | \ / | | \BC FG JKL NP RS UW YZ•Find out how are we going to implement insertion and deletion in a B-Tree that is guaranteed?•InsertionoKey: how do we (1) not create new levels at a level below current leaves, (2) insert if a leaf is already full?oIdea: node splittingT = 3 (full = 5 keys)Leaf: PQRST Parent: NWSplit leaf at RNew Leaves: PQ && ST new Parent: NRWRedistribute any sub-leavesoCodeSPLIT(x)//x is fullK kt(x)Create node xLfrom k1(x)…kt-1(x)Create xRfrom kt+1(x)…k2t-1(x)Move k into parent of xAdd pointers to xL, xRon either side of koProblems:What if the parent is full?•Make sure it never happensWhat if x is root?•create a new rootWhat is the parent?•Always go down, never upoIdea: do recursive DoINsert(x,k)o*Invariant: when we call DoInsert(x,k),Either x is rootOr x’s parent is not fulloCode:Insert(T, k)DoInsert(T.root, k)DoInsert(T....
View Full Document