1 / 18

2620001 Data Structures

2620001 Data 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.

lowri
Download Presentation

2620001 Data Structures

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. 2620001Data Structures Search Trees

  2. 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.

  3. 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

  4. 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 }

  5. 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

  6. 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

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

  8. Threaded Tree Example 6 8 3 1 5 7 11 9 13

  9. 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

  10. Threaded Tree Traversal Output 1 3 6 8 3 1 5 7 11 9 13 Follow thread to right, print node

  11. 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

  12. Threaded Tree Traversal Output 1 3 5 6 6 8 3 1 5 7 11 9 13 Follow thread to right, print node

  13. 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

  14. 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

  15. 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

  16. 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

  17. 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

  18. Example - 2

More Related