I’ll go first: During the union step of union find, we emphasized that the canonical element of the larger set (in terms of # of elements, ‘union-by-weight’) remains canonical of the union’d set. Kozen points out that this keeps the trees in logarithmic height. Another possible way is to union-by-rank where the height of the tree is used instead of the # of elements. Show that this approach also leads to logarithmic height/depth trees.

A: Pretty straight forward. Follows a solution to one of the homework problems. A tree’s height is increased only when unioned with a tree of the same height. Starting with N sets of 1 element each they form N/2 sets of height 1. These then make N/4 sets of height 2 -> N/8 sets of height 3 etc.

Follow up: If both methods produce logarithmic height trees, then why do we prefer union-by-weight?

A: The issue comes up with path compression. Compressing a path may reduce the height of a tree, but it is difficult to know when and by how much. Continuing to union based on not-up-to-date heights can result in much deeper trees. However, path compression does not change the weight of the tree and therefore remains optimal for unions with path compression working.

]]>Question about the Midterm. Will the midterm test us content related to the lectures or nothing is impossible?

]]>In general, on homework, quizzes , or exam, when it’s not clear what’s wanted, you should make reasonable assumptions and state them clearly. I will accept anything reasonable.

In the case of the bag heap problem, I hadn’t thought about what happens when you need to increase the size of the array. Now that you’ve drawn my attention to it, I like the problem even more, as it points out even in this simple situation, the importance of amortizedES analysis.

Thanks for bringing it to my attention! And YES, dealing with the doubling makes it an even nicer problem.

— manuel

]]>