Prove that the height of an AVL tree is bound by O(logn).
and What is the least number of nodes in an AVL tree of height 25? (all work on both questions provided)
`Hey,
Note: Brother if you have any queries related the answer please do comment. I would be very happy to resolve all your queries.
Proof: Let n(h) be the minimum number of internal nodes in an AVL tree of height h.
n(1)=1 and n(2)=2. So the lemma holds for h=1 and h=2.
Here comes the key point.
Consider an AVL tree of height h≥3 and the minimum number of
nodes. This tree is composed of a root, and two subtrees. Since the
whole tree has the minimum number of nodes for its height so do the
subtrees. For the big tree to be of height h, one of the subtrees
must be of height h-1. To get the minimum number of nodes the other
subtree is of height h-2.
Why can't the other subtree be of height h-3 or h-4?
The height of siblings can differ by at most 1!
What the last paragraph says in symbols is that for h≥3,
n(h) = 1+n(h-1)+n(h-2)
The rest is just algebra, i.e. has nothing to do with trees, heights, searches, siblings, etc.
n(h) > n(h-1) so n(h-1) > n(h-2). Hence
n(h) > n(h-1)+n(h-2) > 2n(h-2)
Really we could stop here. We have shown that n(h) at least doubles when h goes up by 2. This says that n(h) is exponential in h and hence h is logarithmic in n. But we will proceed slower. Applying the last formula i times we get
For any i>0, n(h) > 2in(h-2i) (*)
Let's find an i so that h-2i is guaranteed to be 1 or 2, since
this would guarantee that n(h-2i) ≥ 1.
I claim i = ⌈h/2⌉-1 works.
If h is even h-2i = h-(h-2) = 2
If h is odd h-2i = h - (2⌈h/2⌉-2) = h - ((h+1)-2) = 1
Now we plug this value of i into equation (*) and get for h≥3
n(h) > 2in(h-2i)
= 2⌈h/2⌉-1n(h-2i)
≥ 2⌈h/2⌉-1(1)
≥ 2(h/2)-1
Theorem: the height of an AVL tree storing n items is O(log(n)).
Proof: From the lemma we have n(h) > 2(h/2)-1.
Taking logs gives log(n(h)) > (h/2)-1 or
h < 2log(n(h))+2
Since n(h) is the smallest number of nodes possible for an AVL tree of height h, we see that h < 2 log(n) for any AVL tree of height h.
2)
For h=25
n>2^((h-2)/2)
So,
n=2897
Kindly revert for any queries
Thanks.
Prove that the height of an AVL tree is bound by O(logn). and What is the...
1. AVL tree is a tree with a node in the tree the height of the left and right subtree can differ by at most _, meaning every 2. The height of the AVL tree is_ (In Big-O notation) 3. (True False) Below tree is an AVL tree. 4. (True False) Both of the below trees are not AVL tree since they are not perfectly balanced. 5. Inserting a new node to AVL tree can violate the balance condition. For...
Question 1 1 pts What is the maximum height of any AVL-tree with 7 nodes? Assume that the height of a tree with a single node is 0. a N 5 Question 2 1 pts So get the sorted list from an AVL tree we need to do a postorder traversal inorder traversal preorder traversal
Show that the tree height of a height-balanced binary search tree with n nodes is O(log n). (Hint: Let T(h) denote the fewest number of nodes that a height-balanced binary search tree of height h can have. Express T(h) in terms of T(h-1) and T(h-2). Then, find a lower bound of T(h) in terms of T(h-2). Finally, express the lower bound of T(h) in terms of h.)
java AVL tree a). What are the conditions that must exist in a binary tree for calling the left and the right rotation? b). What is the smallest height that a tree of 1000 nodes can be? What is the biggest? Please be very specific, thank you.
Assume the following notation/operations on AVL trees. An empty AVL tree is denoted E. A non-empty AVL tree T has three attributes The key T.key is the root node's key. The left child T.left is Ts left subtree, which is an AVL tree (possibly E). The right child T.right is T's right subtree, which is an AVL tree (possibly E). (a) 5 marsl Write a function RANGECOUNT(T, lo, hi) to count the number of nodes in an AVL tree with...
Assume the following notation/operations on AVL trees. An empty AVL tree is denoted E. A non-empty AVL tree T has three attributes: • The key T.key is the root node’s key. • The left child T.left is T’s left subtree, which is an AVL tree (possibly E). • The right child T.right is T’s right subtree, which is an AVL tree (possibly E). (a) [5 marks] Write a function RangeCount(T, lo, hi) to count the number of nodes in an...
Data structures c++ 1- What is the search time in an AVL tree with n nodes. Select one or more: a. O(2^n) b. O(height * log n) c. O(log n) d. O(height) e. O(log height) f. O(n) g. O(1) h. O(2^height)
1. In a heap, the upper bound on the number of leaves is: (A) O(n) (B) O(1) (C) O(logn) (D) O(nlogn) 2. In a heap, the distance from the root to the furthest leaf is: (A) θ(nlogn) (B) θ(logn) (C) θ(1) (D) θ(n) 3. In a heap, let df be the distance of the furthest leaf from the root and let dc be the analogous distance of the closest leaf. What is df − dc, at most? (A) 1 (C)...
True or false? (a) An insertion in an AVL tree with n nodes requires Θ (log(n)) rotations. (b) A set of numbers are inserted into an empty BST in sorted order and inserted into an empty AVL tree in random order. Listing all elements in sorted order from the BST is O (n), while listing them in sorted order from the AVL tree is O (log(n)). (c) If items are inserted into an empty BST in sorted order, then the...
There are 800 elements which need to be stored in an AVL tree. What is the height of the AYL tree in the worst case? What is the height of the AYL tree in the best case?