304 views
0 votes
0 votes
How do we find the diameter of a Binary tree?

I have come to below algorithm. Please let me know if it works

(1)Use BFS on root's left subtree to find the last processed node say node1.

(2)Use BFS on root's right subtree to find the last processed node say node 2.

(3)Now we again run BFS from node1 as source and we keep counting the number of nodes that appear before our node2 appears. This count will give us the diameter.

Please log in or register to answer this question.

Related questions

1 votes
1 votes
0 answers
3
Rohit Gupta 8 asked Dec 25, 2017
1,141 views
If the average depth of a node in an $n$-node binary search tree is $O(\log{n})$, then the height of the tree is$O(n\log{n})$$O(n)$$O(\log{n})$$O(\sqrt(n\log{n}))$
0 votes
0 votes
2 answers
4
Aman Bisht asked Jun 12, 2017
1,119 views
The height of a binary tree having 'i' nodes at level 'i' considering root to be at level 1 is . where 'n' is the total no of nodes in the tree.A. O(logn)B. O(n)C. O(R...