2620001 Data Structures
180 likes | 313 Vues
This article explores B+-Trees and Standard Tries, highlighting their structures and functionalities. B+-Trees are balanced trees designed for efficient searching, allowing between [n/2] and n children per node while maintaining equal path lengths from root to leaf. The article details operations such as searching (log_d(n)), insertion, and deletion. For Standard Tries, a character-labelled ordered tree is described, showcasing how strings are derived from its structure. Additionally, Threaded Binary Trees are discussed, addressing space efficiency in inorder traversals and their respective traversal algorithms.
2620001 Data Structures
E N D
Presentation Transcript
2620001Data Structures Search Trees
B+ - Tree Structure • A B+ - Tree is in the form of a balanced tree in which every path from the root of the tree to a leaf of the tree is the same length. • Each nonleaf node in the tree has between [n/2] and n children, where n is fixed. • B+ - Trees are good for searches, but cause some overhead issues in wasted space.
B+ Trees: Summary • Searching: • logd(n) – Where d is the order, and n is the number of entries • Insertion: • Find the leaf to insert into • If full, split the node, and adjust index accordingly • Similar cost as searching • Deletion • Find the leaf node • Delete • May not remain half-full; must adjust the index accordingly
Standard Tries • The standard trie for a set of strings S is an ordered tree such that: • Each node but the root is labeled with a character • The children of a node are alphabetically ordered • The paths from the external nodes to the root yield the strings of S • Example: standard trie for the set of strings S = { bear, bell, bid, bull, buy, sell, stock, stop }
Trie / Suffix Tree • A tree representing a set of strings. c a { aeef ad bbfe bbfg c } b e b d e f c f e g
Threaded Binary 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 Example 6 8 3 1 5 7 11 9 13
Threaded Binary 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 Output 1 3 6 8 3 1 5 7 11 9 13 Follow thread to right, print node
Threaded Tree Traversal Output 1 3 5 6 8 3 1 5 7 11 9 13 Follow link to right, go to leftmost node and print
Threaded Tree Traversal Output 1 3 5 6 6 8 3 1 5 7 11 9 13 Follow thread to right, print node
Threaded Tree Traversal Output 1 3 5 6 7 6 8 3 1 5 7 11 9 13 Follow link to right, go to leftmost node and print
Threaded Tree Traversal Output 1 3 5 6 7 8 6 8 3 1 5 7 11 9 13 Follow thread to right, print node
Threaded Tree Traversal Output 1 3 5 6 7 8 9 6 8 3 1 5 7 11 9 13 Follow link to right, go to leftmost node and print
Threaded Tree Traversal Output 1 3 5 6 7 8 9 11 6 8 3 1 5 7 11 9 13 Follow thread to right, print node
Threaded Tree Traversal Output 1 3 5 6 7 8 9 11 13 6 8 3 1 5 7 11 9 13 Follow link to right, go to leftmost node and print