Diameter of a binary tree

The diameter of a tree (sometimes called the width) is the number of nodes on the longest path between two leaves in the tree.

Write  a program to find the diameter of a binary tree.


  1. int diameter(Tree * t)
    if (t == 0) return 0;

    int lheight = height(tree->left);
    int rheight = height(tree->right);

    int ldiameter = diameter(tree->left);
    int rdiameter = diameter(tree->right);

    return max(lheight + rheight + 1,


Post a Comment

Popular posts from this blog