Tuesday, August 23, 2011

Find the diameter of a tree

This is a typical problem of recursion. 

The diameter of a tree  is the number of nodes on the longest path between two leaves in the tree. So you can compute it as the max among the height for the left subtree, the height of the right subtree and the longest path between two leaves passing through the root. 

1 comment:

  1. http://tech-queries.blogspot.com/2010/09/diameter-of-tree-in-on.html

    ReplyDelete