answersLogoWhite

0

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);

User Avatar

Wiki User

14y ago

What else can I help you with?

Related Questions

How do you calculate the height of a binary tree?

To calculate the height of a binary tree, you can use a recursive algorithm that traverses the tree and keeps track of the height at each level. The height of a binary tree is the maximum depth of the tree, which is the longest path from the root to a leaf node.


What are the properties of binary tree?

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)?


What is the size of the tree with depth 3?

7 its a binary tree


What is the formula to calculate the height of a binary tree?

The formula to calculate the height of a binary tree is h log2(n1) - 1, where h is the height of the tree and n is the number of nodes in the tree.


If a binary tree it have 18 nodes what is the minimum depth of the tree?

3


What is the maximum height of a binary tree with a given number of nodes?

The maximum height of a binary tree with 'n' nodes is 'n-1'.


The height of Complete Binary tree is in terms of :option1. n2. logn3. n^2?

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.


What is the minimum number of nodes in a binary tree of depth k?

if u assign a 0th level to root of binary tree then,the minimum no. of nodes for depth K is k+1.


How to calculate the height of a binary tree?

To calculate the height of a binary tree, you can use a recursive algorithm that finds the maximum height of the left and right subtrees, and then adds 1 to the maximum height. This process is repeated for each node in the tree until the height of the entire tree is calculated.


How to find the height of a binary tree?

To find the height of a binary tree, you can use a recursive algorithm that calculates the height of the left and right subtrees, and then returns the maximum height plus one. This process continues until the height of the entire tree is calculated.


What is the difference between height and depth of a tree?

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.....


What is the height of a binary search tree?

The height of a binary search tree is the maximum number of edges from the root node to a leaf node. It represents the longest path from the root to a leaf in the tree.