While solving problems of Expected value I came about this: Prove that, if we pick a random leaf from a binary tree with k leaves, then the expected height of this leaf is at least log(k).
Can anyone give a hint on how to proceed?
Related
I know what Binary search tree is and I know how they work. But what does it take for it to become a skewed tree? What I mean is, do all nodes have to go on one side? or is there any other combination?
Having a tree in this shape (see below) is the only way to make it a skewed tree? If not, what are other possible skewed trees?
Skewed tree example:
Also, I searched but couldn't find a good solid definition of a skewed tree. Does anyone have a good definition?
Figured out a skewed Tree is the worst case of a tree.
`
The number of permutations of 1, 2, ... n = n!
The number of BST Shapes: (1/n+1)(2n!/n!n!)
The number of skewed trees of 1, 2, ....n = 2^(n-1)
`
Here is an example I was shown:
http://i61.tinypic.com/4gji9u.png
A good definition for a skew tree is a binary tree such that all the nodes except one have one and only one child. (The remaining node has no children.) Another good definition is a binary tree of n nodes such that its depth is n-1.
A binary tree, which is dominated solely by left child nodes or right child nodes, is called a skewed binary tree, more specifically left skewed binary tree, or right skewed binary tree.
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.
Can anyone mathematically prove me why the following BST definition is always true by using the fact that the height of a BST is always logN where N is the number of nodes.
"a binary tree in which the left and right subtrees of every node differ in height by no more than 1."
How many binary tree shapes of N nodes are there with height N-1?
Also, how would you go about proofing by induction?
So binary tree of height n-1 with node n means all node will have only 1 child, sort of chain like structure? So number of binary tree will be different permutation of n numbers which is n. Am I thinking in the right direction?
You are thinking in the right direction and you have correctly transformed the original problem to a simple one. However what is strange is that it is explicitly stated that the tree is "binary" when in fact the statement dictates even tighter constraint.
What is the name of the binary tree (or the family of the binary
trees), that is balanced, and has the minimum number of nodes
possible for its height?
Well this is special kind of tree not the AVL tree.
if the binary tree is balanced then, it height is a function of its nodes (n). height = log2n. so a balanced tree don't have a range of heights.
The minimum number of nodes a completely balanced binary tree can have for height d is 2^(d-1)+1. As far as i know this type doesn't have a name.
The maximal number of nodes is 2^d. This is called a complete tree. All layers are completely full and each node has either 2 or zero childern(implied).
Red-black tree?
Any one from http://en.wikipedia.org/wiki/Self-balancing_binary_search_tree#Implementations?
The name of the binary tree (or the family of the binary trees), that has the minimum number of nodes possible for its height is a linked list :D