ta3sol_old - subtree rooted at u color[u = gray u is...

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

View Full Document Right Arrow Icon
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 ...
Image of page 1
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

  • Left Quote Icon

    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.

    Student Picture

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

  • Left Quote Icon

    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.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    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.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern