Solution: Find Minimum Diameter After Merging Two Trees
Understand how to use breadth-first search to find the diameter of two trees and compute the minimal diameter after merging them by connecting their central nodes. This lesson guides you through building adjacency lists, performing BFS to identify farthest nodes, and applying a formula to optimize the combined tree 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 edge. ...