Problem:
Find the diameter of a binary tree.
Solution:
Complexity: O(n), where n = no of nodes
Code:
Find the diameter of a binary tree.
Solution:
- Do Post order traversal
- if Left Max path + Right Max path > Max then
- Max = Left Max path + Right Max path
- return 1 + MAX(Left Max path length + Right Max path length)
Complexity: O(n), where n = no of nodes
Code:
No comments:
Post a Comment