Tap here to switch tabs
Problem
Submissions
Solution

Solution: Diameter of Binary Tree

Statement

Naive approach

The naive approach will be to pick one node, find the distance to every other node from the selected node, and keep track of the maximum value. Repeat this process with all the nodes of the tree. After this process, we’ll have the maximum possible distance between the two nodes. That will be the diameter of the tree.

The time complexity for the naive approach will be O(n2)O(n^2) ...

Tap here to switch tabs
Problem
Submissions
Solution

Solution: Diameter of Binary Tree

Statement

Naive approach

The naive approach will be to pick one node, find the distance to every other node from the selected node, and keep track of the maximum value. Repeat this process with all the nodes of the tree. After this process, we’ll have the maximum possible distance between the two nodes. That will be the diameter of the tree.

The time complexity for the naive approach will be O(n2)O(n^2) ...