1 / 26

Discussion Section Assignment 7

Discussion Section Assignment 7. Leftist Tree Tournament winner, Loser Tree Binary Search Tree. Hadi Hajimiri (hadi@cise.ufl.edu). Leftist Tree (leftist heap).  s-value: The distance to the nearest leaf The right descendant of each node has the lower s-value

thalia
Download Presentation

Discussion Section Assignment 7

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. Discussion SectionAssignment 7 • Leftist Tree • Tournament winner, Loser Tree • Binary Search Tree Hadi Hajimiri (hadi@cise.ufl.edu)

  2. Leftist Tree (leftist heap) •  s-value: The distance to the nearest leaf • The right descendant of each node has the lower s-value • In min (max) leftist tree the root contains the minimum (maximum) item • To delete a minimum item (in min leftist tree), we remove the root and the left and right sub-trees are then merged (melded)

  3. Melding in max leftist tree (example)

  4. Melding in max leftist tree (cont.)

  5. Melding in max leftist tree (cont.)

  6. Melding in max leftist tree (cont.)

  7. Melding in max leftist tree (cont.)

  8. Melding in max leftist tree (cont.)

  9. Melding in max leftist tree (cont.)

  10. Melding in max leftist tree (cont.)

  11. Melding in max leftist tree (cont.)

  12. Melding in max leftist tree (cont.)

  13. Melding in max leftist tree (cont.)

  14. Initializing a height biased leftist tree (HBLT) • Two ways: • Merge each node one at a time into one HBLT O(nlogn) • Use a queue to store each node and resulting tree. The first two items in the queue are removed, merged, and placed back into the queue. O(n)

  15. Tournament winner, Loser Tree • In a min (max) winner tree, the player with the smaller (larger) value wins. • In a loser tree, in each internal node, the loser of the match played at that node is recorded. • Reduces the work needed to determine the players of each match after replacing the winner.

  16. Min Winner Tree

  17. Min loser Tree

  18. Replacing the winner

  19. Binary Search Tree (BST) • Properties: • Every element has a key (or value), and no elements have the same key. • The keys in the left subtree of the root are smaller than the key in the root. • The keys in the right subtree of the root are larger than the key in the root. • The left and right subtrees of the root are also binary search trees.

  20. Inserting elements into BST Insert the keys 9, 2, 7, 11, 16, 15, 1 into the tree in this order.

  21. Inserting elements into BST (cont.) Insert the keys 9, 2, 7, 11, 16, 15, 1 into the tree in this order.

  22. Inserting elements into BST (cont.) Insert the keys 9, 2, 7, 11, 16, 15, 1 into the tree in this order.

  23. Inserting elements into BST (cont.) Insert the keys 9, 2, 7, 11, 16, 15, 1 into the tree in this order.

  24. Inserting elements into BST (cont.) Insert the keys 9, 2, 7, 11, 16, 15, 1 into the tree in this order.

  25. Inserting elements into BST (cont.) Insert the keys 9, 2, 7, 11, 16, 15, 1 into the tree in this order.

  26. Inserting elements into BST (cont.) Insert the keys 9, 2, 7, 11, 16, 15, 1 into the tree in this order.

More Related