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
 Spring '10
 may
 English, Graph Theory, Vertex, size, tree centroid decomposition

Click to edit the document details