Diameter of Tree
Mon Jan 10 2022 06:56:11 GMT+0000 (Coordinated Universal Time)
Saved by @vaibhav_55
Following,is the algo to find the diameter of a tree. Step 1: choose any random node and run dfs from it and find the farthest node from it. Step 2:from the found node again run the dfs and find the again the farthest node. Step 3:now,the distance of the farthest node found in 2nd step from the node from which we ran dfs in 2nd step is diameter.
Comments