Data Structures & AlgorithmsHardGATE CS · ICPC regional
A tree has the vertices C, E, G, K, N, S, T, V, Z and the edges T–K, K–E, K–V, K–S, S–N, N–C, C–G, G–Z. A centroid is a vertex whose removal leaves no connected component with more than n/2 vertices. Which vertex is the centroid?
- A. Z
- B. T
- C. S
- D. E
Correct answer: C. S
Removing S leaves components of at most 4 vertices, while every other vertex leaves a component bigger than n/2. The highest-degree vertex K is a common wrong guess.
Practise more Trees, Graphs, Recursion and Dynamic Programming questionsTrees, Graphs, Recursion and Dynamic Programming: notes and key points
More Trees, Graphs, Recursion and Dynamic Programming questions
- A grid has 3 rows and 3 columns with these values (top to bottom): 787 591 837 A path moves between side-adjacent cells (up, down, left or…
- Consider this function: python def g(n): if n < 3: return n if n % 2 == 0: return g(n - 3) + g(n - 2) return g(n - 1) - 1 What value does…
- Consider this recursive function: python def f(n): if n <= 1: return f(n - 1) if n % 2 == 0: f(n - 2) How many times is f called in total…
- A bipartite graph has left side P1, P2, P3, P4 and right side Q1, Q2, Q3, Q4, with edges P1–Q2, P1–Q3, P1–Q1, P2–Q3. What is the size of a…
- A tree has the vertices A, C, D, F, G, M, P, S, X, Y and the edges A–M, A–S, M–Y, A–F, M–D, D–X, Y–C, F–G, S–P. A set D dominates the tree…
- A grid has 5 rows and 7 columns (rows listed top to bottom; '.' is an open cell, '#' a wall): .#..... ....#.. .#####. .#..... ..#…