954,500 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

binary trees

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?

cuperman
Newbie Poster
3 posts since Oct 2004
Reputation Points: 10
Solved Threads: 0
 

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

kunal_ktr
Newbie Poster
10 posts since Oct 2004
Reputation Points: 10
Solved Threads: 0
 

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.

Chainsaw
Posting Pro in Training
436 posts since Jun 2004
Reputation Points: 36
Solved Threads: 11
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You