Solution: Find Minimum Diameter After Merging Two Trees
Understand how to solve the problem of finding the minimum diameter after merging two trees by applying the tree breadth-first search pattern. This lesson guides you through calculating the diameters of individual trees and using a formula to connect them optimally. You'll learn to build adjacency lists, perform BFS to find farthest nodes, and combine the results to minimize the overall diameter.
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 ...