Data Structures & AlgorithmsHardGATE CS
A tree on vertices 1–9 has edges 2–1, 3–2, 4–2, 5–2, 6–5, 7–4, 8–5, 9–7. What are its diameter and radius, and which vertex/vertices form its centre?
- A. Diameter 5, radius 2, centre {2, 4}
- B. Diameter 6, radius 3, centre {2, 4}
- C. Diameter 5, radius 3, centre {2, 4}
- D. Diameter 5, radius 3, centre {2}
Correct answer: C. Diameter 5, radius 3, centre {2, 4}
Eccentricities give diameter 5 and radius 3 = ⌈5/2⌉; the centre is the middle of every longest path, here 2, 4 (one vertex if the diameter is even, two adjacent ones if odd). The highest-degree vertex need not be the centre.
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
- An undirected graph has edges A–E, A–G, A–H, B–H, C–E, D–F, D–H, E–G, F–H, G–H. BFS starts at A and always scans neighbours in…
- Lectures occupy half-open intervals [start, end): [2, 7), [6, 11), [8, 14), [9, 14), [10, 16), [13, 16), [13, 20), [14, 20). A lecture…
- A binary tree with distinct labels has INORDER D F I E A C H G B and LEVEL-ORDER D G C B E H F A I. What is its postorder traversal?
- A binary search tree holds exactly the keys 10, 17, 35, 59, 61, 68, 84, 91. Which ONE of the following sequences can be its PREORDER…
- DFS on the directed graph with adjacency lists A: BE; B: –; C: AD; D: AG; E: DF; F: D; G: E starts at A (scanning lists in the order…
- Keys 87, 36, 57, 23, 95, 88, 77 inserted in this order build a BST. How many of the 7! orderings of these same 7 keys, inserted into an…