HW2sol - COT 5405 Fall 09 Homework 2 Solution 1. (10pts, 1...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
COT 5405 Fall 09 Homework 2 Solution 1. (10pts, 1 page) Prove that every node has rank at most ( lg n ) in union-Find algorithm with two heuristics (1) union by rank and (2) path compression. Sol: By Induction: Claim: A node with rank r, then it is the root of a subtree of size at least 2 r . Base case: A node of rank 0 is the root of a subtree that contains at least itself (and so is of size = at least 1). Inductive case: A node X can have rank ( r + 1) only if,at some previous stage, it had a rank r and it was the root of a tree that was joined with another tree whose root had rank r . Then X became the root of the union of the two trees. Each tree, by inductive hypothesis is of size at least 2 r , and so now X is the root of a tree of size at least 2 r + 2 r = 2 ( r +1) . Now the number of nodes in the forest is n and we have at least 2 r nodes in every tree with rank r .So, n 2 r r ≤ ⌊ ( lg n ) 2. (15pts, 1/2 page per part) Consider the following code segment: for i = 1 to n makeset( i ) for i = 1 to n 1 union(±nd( i ), ±nd( i + 1)) for i = 1 to n ±nd( i ) For each of the following cases, analyze the time complexity of the above
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 01/15/2012 for the course COT 5405 taught by Professor Ungor during the Fall '08 term at University of Florida.

Page1 / 3

HW2sol - COT 5405 Fall 09 Homework 2 Solution 1. (10pts, 1...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online