Data Structures & AlgorithmsHardProduct-company placement
A tree on vertices 1–9 has edges 2–1, 3–1, 4–3, 5–2, 6–4, 7–6, 8–6, 9–8. What are its diameter and radius, and which vertex/vertices form its centre?
- A. Diameter 7, radius 4, centre {3, 4}
- B. Diameter 7, radius 3, centre {3, 4}
- C. Diameter 8, radius 4, centre {3, 4}
- D. Diameter 7, radius 4, centre {6}
Correct answer: A. Diameter 7, radius 4, centre {3, 4}
Eccentricities give diameter 7 and radius 4 = ⌈7/2⌉; the centre is the middle of every longest path, here 3, 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
- Five matrices have dimensions 12×10 , 10×4 , 4×6 , 6×6 , 6×8. What is the minimum number of scalar multiplications needed to compute their…
- An undirected graph has edges A–D, A–F, A–G, B–C, B–F, C–D, C–E, E–G, F–G. An ITERATIVE DFS starts with stack [A]; it pops a vertex, skips…
- What is the length of the longest common subsequence of ONTOLOGY and TOPOLOGY, and how many DISTINCT longest common subsequences (as…
- Edit distance between MARTIAN and COMPILER where insert and delete cost 1 each but a substitution costs 2: what is the minimum total cost?
- Dijkstra's algorithm runs from A on the directed graph A→C (4), B→A (1), B→F (6), C→B (7), C→E (12), C→F (6), D→C (3), E→A (15), E→B (3)…
- The weighted undirected graph A–B (27), A–D (3), A–E (1), B–C (25), B–D (8), B–E (18), B–F (5), C–E (9) has a unique MST. What is the…