height(node):
if node == null:
return 0
else:
max(height(node.L), height(node.R)) + 1
/*Function to print level order traversal of tree*/
getMaxWidth(tree)
maxWdth = 0
for i = 1 to height(tree)
width = getWidth(tree, i);
if(width > maxWdth)
maxWdth = width
return width
/*Function to get width of a given level */
getWidth(tree, level)
if tree is NULL then return 0;
if level is 1, then return 1;
else if level greater than 1, then
return getWidth(tree->left, level-1) +
getWidth(tree->right, level-1);
A complete binary tree is "a binary tree in which evert level, except possibly the deepest, is completely filled. At depth n, the height of the tree, all nodes must be as far left as possible."
According the the above definition by the NIST, this means that the minimum height of a complete binary tree is 1.
A binary tree of n elements has n-1 edgesA binary tree of height h has at least h and at most 2h - 1 elementsThe height of a binary tree with n elements is at most n and at least ?log2 (n+1)?
7 its a binary tree
3
if u assign a 0th level to root of binary tree then,the minimum no. of nodes for depth K is k+1.
The height of a complete binary tree is in terms of log(n) where n is the number of nodes in the tree. The height of a complete binary tree is the maximum number of edges from the root to a leaf, and in a complete binary tree, the number of leaf nodes is equal to the number of internal nodes plus 1. Since the number of leaf nodes in a complete binary tree is equal to 2^h where h is the height of the tree, we can use log2 to find the height of a complete binary tree in terms of the number of nodes.
height and depth of a tree is equal... but height and depth of a node is not equal because... the height is calculated by traversing from leaf to the given node depth is calculated from traversal from root to the given node.....
Level and height are same, but the depth is the is the maximum distance from any node to root. It is reverse in the case of height.
Check this out! http://stackoverflow.com/questions/575772/the-best-way-to-calculate-the-height-in-a-binary-search-tree-balancing-an-avl
Complete Binary tree: -All leaf nodes are found at the tree depth level -All nodes(non-leaf) have two children Strictly Binary tree: -Nodes can have 0 or 2 children
Complete Binary tree: All leaf nodes are found at the tree depth level and All non-leaf nodes have two children. Extended Binary tree: Nodes can have either 0 or 2 children.
In the worst case a binary search tree is linear and has a height equal to the number of nodes. so h=O(h).
0 for an empty tree 1 for a leaf otherwise depth (t) = 1 + max (depth (t->left), depth (t->right))