Is the height of a tree with respect to nodes or path? - binary-tree

In samsung technical test Question was asked whether this statement is true or not:
Maximum number of nodes in a binary tree is 2^(h+1)-1 where h is the height of tree.
I think it's false because according to Schaum's Series TMH height is defined as the maximum number of nodes till the leaf is reached.
Is it correct or not?

The statement is correct. A zero-height binary tree has at most one node, a tree of height one has at most 3 nodes and so on.

There are two conventions to define the height of binary 1) Maximum Number of nodes from root to leaf 2) Maximum Number of edges from root to leaf
Please refer following article
http://www.geeksforgeeks.org/iterative-method-to-find-height-of-binary-tree/

True, Maximum number is reached when each node has two children - so we have power of 2. Just draw the tree with all leafs at each level and you will see the formula.

according to this wikipedia article that statement is true

Related

Maximum & minimum height of a binary tree

According to my textbook when N nodes are stored in a binary tree H(max) = N
According to outside sources when N nodes are stored in a binary tree H(max) = N - 1
Similarly
According to my textbook when N nodes are stored in a binary tree H(min) = [log2N+1]
According to outside sources when N nodes are stored in a binary tree H(min) = [log2(N+1)-1]
Which one is right and which is wrong? Are they supposed to be used in different situations. In this case what would be the maximum height of a tree with 32 nodes?
I have been looking through my resources to understand this concept, and for some reason all my sources have different answers. I can calculate height when a binary tree is pictorially represented because that would involve number of nodes in each subtree. What about when only the number of nodes are given?
Obviously it has to do with the definition of height. If the height is defined by the number of nodes traversed from top to bottom then the max height is N. If it's defined as the number of hops between nodes, then it's N-1. Same goes for minimum height. That said, what counts is it's respectively O(N) and O(log N).

Is it possible to determine AVL tree balanced or not if instead of height depth is given?

In question it is given we can use depth only and not height.
(As we know for height we can say if difference between height of left subtree and height of right subtree is is at most one then it will be balanced)
Using depth can we find a way to prove tree balanced or not?
I tried by finding relation between different depth trees
What I got is that
If depth max = n
Then there must be n nodes whose depth is n-1
But this is just one condition I got.
It is not sufficient condition
( You can ignore my approach and try other thing .As there is no condition on approaching the problem)
The principle is the same as with height: use the following logic:
For each node do:
Get the maximum among the depths of all the nodes in the left subtree. Default (when no left subtree is present) is the current node's depth.
Get the maximum among the depths of all the nodes in the right subtree. Default (when no right subtree is present) is the current node's depth.
The difference between these two should not be more than 1.
If you implement this with a post-order traversal through the tree, you can keep track of the maximum depths -- needed in the first two steps -- as you traverse the tree.

Height difference between leaves in an AVL tree

What is the maximum difference between any two leaves in an AVL tree? If I take an example, my tree becomes unbalanced, if the height difference is more than 2(for any two leaves), but the answer is the difference can be any value. I really don't understand, how this is possible.Can anyone explain with examples?
The difference in levels of any two leaves can be any value! Definition of AVL describes height difference only on two sub-trees from one node.
So you need to fill subtrees with equal height then add new nodes just to create that single node difference. But nobody said that that subtree doesn't contain some subtrees with the exact same definition. Of course tree is selfbalanced but if we'll be that accurate to not touch it's balance then we can create any height difference between some leaves.
Example with leaf 24 on level 3 and leaf 10 on level 6:
According to the explanation in this Wikipedia article, the balancing operations in an AVL tree successfully aim at rearranging the tree such that the height of any two leaves differs no more than one. This is the key property of the data structure which makes the retrieval of nodes efficient (namely logarithmic in the number of nodes of the tree, as a path from the root to a leaf is traversed in the worst case).

Learning about properties of Trees

I'm trying to learn about Trees and their uses. One part of my class slide said that one definition of a tree is:
The height (maximum distance) of a tree is the maximum level among all of the nodes in the tree.
Node quit sure what that means, can anyone explain? Thanks
The height of a tree is the length of the longest downward path to a leaf from the root.

IOI 2003 : how to calculate the node that has the minimum balance in a tree?

here is the Balancing Act problem that demands to find the node that has the minimum balance in a tree. Balance is defined as :
Deleting any node
from the tree yields a forest : a collection of one or more trees. Define the balance of a node to be the size of the largest tree in the forest T created by deleting that node from T
For the sample tree like :
2 6 1 2 1 4 4 5 3 7 3 1
Explanation is :
Deleting node 4 yields two trees whose member nodes are {5} and {1,2,3,6,7}. The
larger of these two trees has five nodes, thus the balance of node 4 is five. Deleting node
1 yields a forest of three trees of equal size: {2,6}, {3,7}, and {4,5}. Each of these trees
has two nodes, so the balance of node 1 is two.
What kind of algorithm can you offer to this problem?
Thanks
I am going to assume that you have had a looong look at this problem: reading the solution does not help, you only get better at solving these problems by solving them yourself.
So one thing to observe is, the input is a tree. That means that each edge joins 2 smaller trees together. Removing an edge yields 2 disconnected trees (a forest of 2 trees).
So, if you calculate the size of the tree on one side of the edge, and then on the other, you should be able to look at a node's edges and ask "What is the size of the tree on the other side of this edge?"
You can calculate the sizes of trees using dynamic programming - your recurrence state is "What edge am I on? What side of the edge am I on?" and it calculates the size of the tree "hung" at that node. That is the crux of the problem.
Having that data, it is sufficient to iterate through all the nodes, look at their edges and ask "What is the size of the tree on the other side of this edge?" From there, you just pick the minimum.
Hope that helps.
You basically want to check 3 things for every node:
The size of its left subtree.
The size of its right subtree.
The size of the rest of the tree. (size of tree - left - right)
You can use this algorithm and expand it to any kind of tree (different number of subnodes).
Go over the tree in an in-order sequence.
Do this recursively:
Every time you just before you back up from a node to the "father" node, you need to add 1+size of node's total sub trees, to the "father" node.
Then store a value, let's call it maxTree, in the node that holds the maximum between all its subtrees, and the (sum of all subtrees)-(size of tree).
This way you can calculate all the subtree sizes in O(N).
While traversing the tree, you can hold a variable that hold the minimum value found so far.

Resources