Data Structures & AlgorithmsVery hardCodeforces Div 2 C · GATE CS
A tree has the vertices A, E, G, I, K, L, N, O, W and the edges G–W, W–O, O–E, E–L, G–I, G–A, A–K, O–N. A centroid is a vertex whose removal leaves no connected component with more than n/2 vertices. Which vertex is the centroid?
- A. O
- B. G
- C. K
- D. W
Correct answer: D. W
Removing W leaves components of at most 4 vertices, while every other vertex leaves a component bigger than n/2. The highest-degree vertex G 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 tree has vertices A, B, F, H, I, K, M, Q, S and weighted edges (weights in brackets): Q–S (5), Q–M (4), Q–K (1), S–H (3), Q–A (7), K–B…
- A flow network has source S and sink T, with directed arcs and capacities in brackets: S→E (8), S→T (3), B→E (6), B→T (7), E→T (9), C→E…
- Floyd–Warshall runs on vertices 1 to 4 with these arcs u→v (weight): 1→3 (1), 1→4 (4), 2→1 (1), 2→3 (3), 3→1 (12), 3→2 (11), 3→4 (3), 4→1…
- A directed acyclic graph has the vertices C, D, H, I, U, X and the arcs U→I, U→H, U→C, D→I, D→C, X→I, X→C, H→C. Two players alternately…
- A grid has 6 rows and 8 columns (rows listed top to bottom; '.' is an open cell, '#' a wall): ..#..... .#.....# ...##... ....###. #.###…
- Two unmarked jugs hold 5 litres and 9 litres. Allowed operations: fill a jug completely, empty a jug completely, or pour one jug into the…