Discussion Section Assignment 7
description
Transcript of Discussion Section Assignment 7
Leftist Tree Tournament winner, Loser Tree Binary Search Tree
Hadi Hajimiri ([email protected])
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)
2
3
4
5
6
7
8
9
10
11
12
13
Two ways:1. Merge each node one at a time into one HBLT
O(nlogn)2. 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)
14
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.
15
16
17
18
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.
19
Insert the keys 9, 2, 7, 11, 16, 15, 1 into the tree in this order.
20
Insert the keys 9, 2, 7, 11, 16, 15, 1 into the tree in this order.
21
Insert the keys 9, 2, 7, 11, 16, 15, 1 into the tree in this order.
22
Insert the keys 9, 2, 7, 11, 16, 15, 1 into the tree in this order.
23
Insert the keys 9, 2, 7, 11, 16, 15, 1 into the tree in this order.
24
Insert the keys 9, 2, 7, 11, 16, 15, 1 into the tree in this order.
25
Insert the keys 9, 2, 7, 11, 16, 15, 1 into the tree in this order.
26