18

Claim: No, there is no such $\mu$. Proof: We give an infinite sequence of AVL trees of growing size whose weight-balance value tends to $0$, contradicting the claim. Let $C_h$ the complete tree of height $h$; it has $2^{h+1}-1$ nodes. Let $S_h$ the Fibonacci tree of height $h$; it has $F_{h+2} - 1$ nodes. [1,2,TAoCP 3] Now let $(T_h)_{i\geq 1}$ with $T_h ...


4

Augment the tree to store, for each subtree, the minimum of the prefix sums of the sequence of elements in that subtree. Then you can check the supergood condition in $O(\log n)$ time. It's your exercise, so I'll let you work out the details. Hint #1: every prefix can be decomposed into a union of $O(\log n)$ subtrees. Hint #2: the minimum of the prefix-...


3

Both of them will work, and both of them support insertions${}^1$ and deletion${}^2$ of the minimum element in $O(\log n)$ worst-case time (where $n$ is the number of elements currently in the data structure). It really depends what you mean by "better". An AVL tree will have the additional binary-search-tree property that the heaps do not have, and this ...


3

No, it is not an AVL tree. A binary tree is defined to be an AVL tree if $${\text{BalanceFactor}}(N)\in {\{-1,0,1\}} $$ holds for every node $N$ in the tree, where $$\text{BalanceFactor}(N):=\text{Height(RightSubtree(N))} - \text{Height(LeftSubtree(N))}$$ Consider Node 2. Its left subtree is a degenerated tree of height 2. Its right subtree is empty. ...


2

Please skip that article at tutorialspoint. Instead, read this article at GeekforGeeks, which is much better. You may want to check my answer to another question. The common abbreviations for Left rotation, Right rotation, Left-Right rotation, Right-Left rotation are L, R, LR and RL respectively, as expected. These rotations can be applied to all kinds of ...


2

Apparently, you want to rebalance the AVL tree. You can either do a simple left rotation or a right-left rotation. I prefer not to mention right-right rotation since that term is misleading and ambiguous. You can visualize what is happening. Go to AVL tree visualization, a page created by David Galles. Insert 2, 1, 4, 3, 5 in that order. Now look ...


2

It is on the right direction to try some kind of tree augmented with a global counter that stores the number of all unordered pairs of nodes $\{u,v\}$ such that $v.value+u.value \le d$. The kind of tree you are looking for is a balanced (binary) search tree. Being balanced such as an AVL tree, it supports insertion, deletion and lookup of a number with $O(\...


1

Denote by $d(h)$ the minimum height of a leaf in an AVL tree of height $h$. One subtree of the root necessarily has height $h-1$, and the other one has height either $h-2$ or $h-1$ by the defining property of AVL trees. Therefore $$ d(h) = \min(d(h-1),d(h-2)) + 1. $$ Also, one checks that $d(0) = d(1) = 0$ (if one measures height as the maximum number of ...


1

Adding one element to a set, versus deleting one element from a set, are indeed rather symmetric operations. You are right. However, in the case where the sets are represented by a tree, the two operations turn out to be asymmetric. When adding an item one branch may be too long, and one well-chosen rotation will rebalance. When deleting an item one branch ...


1

No it is not. They both have the same running time but the heap is way lighter for a couple of reasons. For the asymptotic running time, note that a heap can be built in linear time meanwhile applying $n$ operations of extract min takes a total of $O(n \log n)$. On the other hand, constructing an AVL tree requires $O(n\log n)$ operations meanwhile traversing ...


1

AVL trees, like all other binary search trees, have the following guarantee: Suppose that $v$ is a node with left child $l$ and right child $r$. If $x$ is a node in the subtree rooted at $l$ and $y$ is a node in the subtree rooted at $r$ then $key(x) \leq key(v) \leq key(y)$. Using this, you can easily prove by induction that the inorder traversal of a ...


1

What you are asking is simply how to balance a binary search tree (BST) $T$. By the way, the phrase "un-balanced AVL tree" is somewhat confusing since AVL tree is height balanced by definition. If there is enough space for a whole new tree, then we can simply construct a new AVL tree from scratch, by removing one element from the $T$ and inserting it to the ...


1

We want to show that the number of nodes $n$ in a height-balanced binary tree with height $h$ grows exponentially with $h$ and at least as fast as the Fibonacci sequence. Let $N_h$ denote the minimum number of nodes in a height-balanced binary tree having height $h$. Recall that in a height-balanced binary tree of height $h$, the subtree rooted at one of ...


1

I think, I should get 37 as the root node 25 as it's left child and 52 as it's right child but I dunno. You plan is correct. What you need to do is a left-right rotation as shown in the third column of the table below. That is, a left rotation at node 25 followed by a right rotation at 52. It is symmetric to the right-left rotation as shown in the fourth ...


Only top voted, non community-wiki answers of a minimum length are eligible