1 / 12

Exercise problems: Union-Find & Height biased Leftist trees

Exercise problems: Union-Find & Height biased Leftist trees. Problem 11.61. Assume that we start with singleton sets and perform unions, using the height rule. Let t be a tree with p nodes created in this way. Prove that the height of t is at most ⌊log 2 p ⌋ + 1. 7. 13. 4. 5. 8. 3.

dick
Download Presentation

Exercise problems: Union-Find & Height biased Leftist trees

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. Exercise problems: Union-Find & Height biased Leftist trees

  2. Problem 11.61 • Assume that we start with singleton sets and perform unions, using the height rule. Let t be a tree with p nodes created in this way. Prove that the height of t is at most ⌊log2p⌋ + 1.

  3. 7 13 4 5 8 3 22 6 9 11 30 10 2 1 20 16 14 12 Recap: Union with Height Rule • Make tree with smaller height a subtree of the other tree. • Break ties arbitrarily. union(7,13)

  4. Proof: • Prove that the number of elements in a tree of height h is at least 2h-1. We shall do this by induction on h. • Base case: use h = 1. A tree of height 1 has exactly 1 >= 2h-1 element/node. • Assume that trees of height h for h < m, where m is an arbitrary integer >= 1, have at least 2h-1 elements.

  5. Proof: (cont.) • Show that all trees of height m + 1 created using the height rule have at least 2melements • How is a tree of height m+1 is created? • Union of two trees of height m • From induction hypothesis a tree of height m has 2m - 1elements • Therefore, the resulting tree has at least 2m elements

  6. Problem 11.62 • Give an example of a sequence of unions that start with singleton sets and create trees whose height equals the upper bound given in previous proof. Assume that each union is performed with the height rule.

  7. Solution: • Any sequence which always combines sets that have the same number of elements will do. • For example, the sequence union(1,2), union(3,4), union(1,3) results in a tree of 4 elements and height 3. • The sequence union(5,6), union(7,8), union(5,7) also results in a height 3 tree with 4 elements. • Performing the operation union(1,5) now results in a height 4 tree with 8 elements.

  8. Problem 11.59 • Give an example of a sequence of unions that start with singleton sets and create trees whose height equals the upper bound (log n). Assume that each union is performed with the weight rule.

  9. Solution: • Similar to 11.62

  10. Problem 12.19 (Height biased Leftist trees) • Consider the array the Elements = [3, 5, 6, 7, 20, 8, 2, 9, 12, 15, 30, 17]. • Draw the max leftist tree created by initialization algorithm from class. • Now insert the elements 10, 18, 11, and 4 (in this order) using the insert method. Show the max leftist tree following each insert. • Perform three remove max operations on the max leftist tree of part (c). Use the remove method. Show the max leftist tree following each remove.

  11. Quick Recap: • We’ll quickly go over the lecture slides on height biased leftist trees for Push(), Pop(), and initializing algorithms.

  12. Solution: • http://www.cise.ufl.edu/~sahni/dsaac/public/exer/c12/e19.htm

More Related