Solution: Find Minimum Diameter After Merging Two Trees
Explore how to compute the minimum diameter of a combined tree formed by connecting two undirected trees. This lesson teaches you to apply breadth-first search twice to find each tree's diameter, then use a formula to determine the optimal minimal diameter after merging the trees. Understand adjacency list construction, BFS traversal, and how to apply these to minimize the longest path in the merged structure.
We'll cover the following...
Statement
You are given two undirected trees: one with edges1 of length edges2 of length edges1[i] = [aᵢ, bᵢ] represents an edge between nodes edges2[i] = [uᵢ, vᵢ] represents an edge in the second tree.
Your task is to connect any node from the first tree to any one node from the second tree using a single ...