ENGLISH
ta3sol_old

# ta3sol_old - This question is referring to a problem of...

• Notes
• 1

This preview shows page 1. Sign up to view the full content.

This question is referring to a problem of tree centroid decomposition. We say that a vertex v c is a centroid of a n -vertex tree T = ( V, E ) if we remove v c generates no subtrees of size more than n/ 2. The algorithm for solving this problem is described as follows. Assume that the input tree is rooted. If not, we can generate such a rooted tree by DFS. Then, we compute and store the size of each subtree rooted at vertex u , in size[ u ]. And a vertex u is a centroid if and only if (a) for each child v i of u , size[ v i ] n/ 2, and (b) n - size [u] n/ 2. Therefore, we can find a centroid by checking the size of each subtree and see whether it satisfies the conditions above. If so, we report that vertex is a tree centroid. Here is the pseudo code of the algorithm. Find_Tree_Centroid(T,root) { for each u in V do // Initialization color[u] = white; Compute_Tree_Size(root); // Compute and store the size of ... // each subtree rooted at u Check_Centroid_Conditions(root); // Check the conditions } Compute_Tree_Size(u) { count = 1; // Initialize count = 1 for each ...
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: // subtree rooted at u color[u] = gray; // u is discovered for each v in Adj(u) do { if (color[v] == white) { // Visit undiscovered vertex subcount = Compute_Tree_Size(v); count = count + subcount; // Accumulate the count for . .. // each subtree of u } } size[u] = count; // Store size of subtree rooted at u return count; // Return the size of subtree rooted at u } Check_Centroid_Conditions(u) { for each u in V do { count = 0; if (n - size[u] <= n/2) for each v in Adj(u) do if (size[v] > n/2) Break out of the inner for loop. output "u is a centroid"; } } } Running time analysis: Initialization takes O ( | V | ) time. The Compute Tree Size () procedure takes O ( | V | ) time to compute the size of each subtree rooted at vertex u . The check in the procedure Check Centroid Conditions takes O ( degree ( u )) time for each vertex u , and sums to O ( | V | ) time for the whole checking process. Thus, the algorithms runs in O ( | V | ) time which is linear. 1...
View Full Document

{[ snackBarMessage ]}

### What students are saying

• As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

Kiran Temple University Fox School of Business ‘17, Course Hero Intern

• I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

Dana University of Pennsylvania ‘17, Course Hero Intern

• The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

Jill Tulane University ‘16, Course Hero Intern