i've referred a couple of datastructure books and both give different definitions for width of a binary tree.
one says its the no of nodes at a level,while another says its the longest path that can be traversed in a binary tree.
can any one help me with a recursive /non recursive algorithm for the second one?

recursive algorithm :
height(tree * ){
if(root==NULL)
return 0;
return 1+max(height(root->left),height(root->right));
}

hope u can write a function for max(par1, par2) also. ok

Generally, a binary tree is a collection of nodes, each with one 'parent' and two 'children', a 'left' child and a 'right' child. In addition, there would be some data or payload.

But from there, folks specialize them in all kinds of ways. For example, 'red/black' trees; search Google for various types of binary trees and their algorithms.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.