Data Structures & AlgorithmsHardProduct-company placement
A tree on vertices 1–9 has edges 2–1, 3–1, 4–1, 5–3, 6–3, 7–6, 8–7, 9–6. What are its diameter and radius, and which vertex/vertices form its centre?
- A. Diameter 5, radius 2, centre {3, 6}
- B. Diameter 5, radius 3, centre {3, 6}
- C. Diameter 6, radius 3, centre {3, 6}
- D. Diameter 5, radius 3, centre {1}
Correct answer: B. Diameter 5, radius 3, centre {3, 6}
Eccentricities give diameter 5 and radius 3 = ⌈5/2⌉; the centre is the middle of every longest path, here 3, 6 (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
- A 4 × 4 grid has rows 3 6 2 5 / 6 9 2 3 / 8 7 2 2 / 4 2 4 9. Moving only right or down from the top-left to the bottom-right cell, what is…
- The words trial, tripod, trie, trip, tried, tree are inserted into an empty trie (one node per character, shared prefixes share nodes…
- Keys 19, 93, 16, 51, 81, 18, 92, 41 inserted in this order build a BST. How many of the 8! orderings of these same 8 keys, inserted into…
- Keys 92, 49, 31, 85, 28, 73, 29, 81, 90 are inserted in that order into an empty AVL tree. What is the preorder traversal of the final tree?
- The words graph, green, greed, grape, grass are inserted into an empty trie (one node per character, shared prefixes share nodes, plus a…
- In the DAG with edges B→E, C→A, C→G, D→A, D→B, D→C, D→F, D→G, F→A, F→B, F→C, how many distinct directed paths are there from D to G, and…