260 likes | 451 Views
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
E N D
Discussion SectionAssignment 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 • 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)
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)
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.
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.
Inserting elements into BST Insert the keys 9, 2, 7, 11, 16, 15, 1 into the tree in this order.
Inserting elements into BST (cont.) Insert the keys 9, 2, 7, 11, 16, 15, 1 into the tree in this order.
Inserting elements into BST (cont.) Insert the keys 9, 2, 7, 11, 16, 15, 1 into the tree in this order.
Inserting elements into BST (cont.) Insert the keys 9, 2, 7, 11, 16, 15, 1 into the tree in this order.
Inserting elements into BST (cont.) Insert the keys 9, 2, 7, 11, 16, 15, 1 into the tree in this order.
Inserting elements into BST (cont.) Insert the keys 9, 2, 7, 11, 16, 15, 1 into the tree in this order.
Inserting elements into BST (cont.) Insert the keys 9, 2, 7, 11, 16, 15, 1 into the tree in this order.