Data Structures & AlgorithmsVery hardGoogle · Trees
A weighted tree has edges A-B 3, A-C 4, B-D 5, B-E 2, C-F 6, F-G 1, F-H 7, E-I 8, D-J 2, H-K 3. What is its diameter (the greatest path length between any two vertices)?
- A. 30
- B. 33
- C. 28
- D. 35
Correct answer: B. 33
The longest path is K-H-F-C-A-B-E-I: 3 + 7 + 6 + 4 + 3 + 2 + 8 = 33; the J-to-K path is shorter at 30.
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
- Which traversal of a binary search tree visits the keys in ascending order?
- Which data structure does breadth-first search (BFS) use to decide which vertex to visit next?
- How many edges does a tree with n vertices have?
- In a min-heap, where is the smallest element always found?
- What is the space needed by the adjacency-matrix representation of a graph with V vertices and E edges?
- Depth-first search is naturally implemented with which of the following?