Top Banner
Leftist Tree Tournament winner, Loser Tree Binary Search Tree Hadi Hajimiri ([email protected])
26

Discussion Section Assignment 7

Jan 27, 2016

Download

Documents

Vourou Vourou

Discussion Section Assignment 7. Leftist Tree Tournament winner, Loser Tree Binary Search Tree. Hadi Hajimiri ([email protected]). Leftist Tree (leftist heap).  s-value: The distance to the nearest leaf The right descendant of each node has the lower s-value - PowerPoint PPT Presentation
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Discussion Section Assignment 7

Leftist Tree Tournament winner, Loser Tree Binary Search Tree

Hadi Hajimiri ([email protected])

Page 2: Discussion Section Assignment 7

 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

Page 3: Discussion Section Assignment 7

3

Page 4: Discussion Section Assignment 7

4

Page 5: Discussion Section Assignment 7

5

Page 6: Discussion Section Assignment 7

6

Page 7: Discussion Section Assignment 7

7

Page 8: Discussion Section Assignment 7

8

Page 9: Discussion Section Assignment 7

9

Page 10: Discussion Section Assignment 7

10

Page 11: Discussion Section Assignment 7

11

Page 12: Discussion Section Assignment 7

12

Page 13: Discussion Section Assignment 7

13

Page 14: Discussion Section Assignment 7

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

Page 15: Discussion Section Assignment 7

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

Page 16: Discussion Section Assignment 7

16

Page 17: Discussion Section Assignment 7

17

Page 18: Discussion Section Assignment 7

18

Page 19: Discussion Section Assignment 7

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

Page 20: Discussion Section Assignment 7

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

20

Page 21: Discussion Section Assignment 7

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

21

Page 22: Discussion Section Assignment 7

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

22

Page 23: Discussion Section Assignment 7

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

23

Page 24: Discussion Section Assignment 7

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

24

Page 25: Discussion Section Assignment 7

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

25

Page 26: Discussion Section Assignment 7

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

26