Docsity

B+ Trees and Threaded Trees: Data Structures for Efficient Indexing, Study notes of Computer Engineering and Programming

Partial preview of the text

Download B+ Trees and Threaded Trees: Data Structures for Efficient Indexing and more Study notes Computer Engineering and Programming in PDF only on Docsity!

B+ Trees  Similar to B trees, with a few slight differences  All data is stored at the leaf nodes ( leaf pages ); all other nodes ( index pages ) only store keys  Leaf pages are linked to each other  Keys may be duplicated; every key to the right of a particular key is >= to that key

B+ Tree Example 9, 16 2, 7 12 18 1 7 3, 4, 6 9 12

B+ Tree Insertion Example 9, 16 2, 7 12 18 1 7 3, 4, 6 9 12

Insert 5

B+ Tree Insertion Example 9, 16 2, 7 12 18 1 7 3, 4, 5,6 9 12

Insert 5

B+ Tree Insertion Example 2 Split index page, move 13 16, 18 3, 4, 6 9 14

B+ Tree Deletion  Delete key and data from leaf page  If leaf page underflows, merge with sibling and delete key in between them  If index page underflows, merge with sibling and move down key in between them

B+ Tree Deletion Example Remove 9 3, 4, 6

B+ Tree Deletion Example Leaf page underflow, so merge with sibling and remove 9 3, 4, 6

Threaded Trees  Binary trees have a lot of wasted space: the leaf nodes each have 2 null pointers  We can use these pointers to help us in inorder traversals  We have the pointers reference the next node in an inorder traversal; called threads  We need to know if a pointer is an actual link or a thread, so we keep a boolean for each pointer

Threaded Tree Code  Example code: class Node { Node left, right; boolean leftThread, rightThread; }

Threaded Tree Traversal  We start at the leftmost node in the tree, print it, and follow its right thread  If we follow a thread to the right, we output the node and continue to its right  If we follow a link to the right, we go to the leftmost node, print it, and continue

Threaded Tree Traversal 8 5 7

Start at leftmost node, print it Output 1