-3

I saw the following claim:

Let T be an AVL tree and TL be the number of nodes in the left sub tree of the root while TR is the number of nodes in the right sub tree of the root. Then: TL = Big Theta (TR) which both means: TL = O(TR) and TL = Big Omega (TR)

at first I though it's simple to be true but what if the left son has 0 nodes and the right son has 1 node? that's still a legal avl tree which contradicts the claim.

Can someone kindly confirm and see what wrong I am doing here?

2 Answers2

2

The claim is false, but that's not a valid proof. It's true that 1 is not O(0); however, this fact is not relevant, because the customary way to define the sequence in question would be to let TL(n) be the maximum (for big-O) or minimum (for big-Omega) number of nodes in the root's left subtree given that the right subtree has n nodes. It's not possible for a valid AVL tree to have an empty left subtree with more than one node in the right, due to the AVL balance property, so this degenerate example is not the infinite family that we need to reason about the asymptotic behavior.

The quantifier structure for f(n) = O(g(n)) is that there exist n0 and c such that for all n ≥ n0, we have f(n) ≤ c g(n). When we negate this statement, the quantifiers flip, so for all n0 and c, there exists n ≥ n0 such that f(n) > c g(n). If we take n0 large, then it excludes your example.

The requirement for an AVL tree to be well-formed is that every subtree is ±1-height balanced. In the most extreme case, the left subtree is complete with height k+1, and the right subtree has the fewest nodes possible to make height k. We get recurrences TL(k), the number of nodes in a complete subtree of height k,

TL(0) = 1
TL(k+1) = 2 TL(k) + 1,

which solves to TL(k) = 2^(k+1) - 1, and TR(k), the number of nodes in a minimal AVL tree of height k,

TR(0) = 1
TR(1) = 2
TR(k+1) = TR(k) + TR(k-1) + 1,

which solves to TL(k) = Fib(k+1) - 1, which is O(1.7^k) and hence not Omega(2^k).

David Eisenstat
  • 64,237
  • 7
  • 60
  • 120
1

The claim is incorrect. To disprove the claim, your counterexample indeed suffices, since 1 is not O(0): There cannot be any (constant) c with

1 <= c * 0.

Note that to prove the claim, one has to ensure both

TL = O(TR) and TR = O(TL)

no matter what TL and TR are (as long as they are possible numbers in a valid AVL-tree). The currently accepted answer is misleading. Note that to show that the claim is false, one does not need a proof. Observe that the claim in the original question does not state that the equalities hold for suffiently large valid TL and TR. Instead, it states that the equalities hold for any valid TL and TR. And that is why MrCalc, the author of the question, seeks confirmation about his counterexample. And here is my confirmation:

MrCalc's counterexample TL=0 and TR=1 indeed disproves the claim.

I do not agree at the statement in the currently accepted answer saying that the inequality 1 is not O(0) is irrelevant. On the contrary, this is a crucial point raised in the original question and the inequality does disprove the claim.

modnar
  • 274
  • 1
  • 6
  • "Observe that the claim in the original question does not state that the equalities hold for suffiently large valid TL and TR" I have a PhD in computer science, so I can tell you that that's not how [big O notation](https://en.wikipedia.org/wiki/Big_O_notation) works. Some authors do omit n_0 but only when they limit their definition to positive-valued functions, which agrees with standard big-O notation (because it's possible to scale up c instead) but cannot be applied to the functions in the question. Either way, this answer is not correct. – David Eisenstat Dec 21 '20 at 19:52
  • You are interpreting the claim `TL = O(TR)` as a statement on a particular instance of a tree (quantified over all trees), in which case `TL` and `TR` would be integers. This would render the claim completely meaningless (i.e. "for any given tree, `TL = O(TR)`). Clearly `TL` and `TR` are to be interpreted as functions of the size of the tree. Then the claim would be meaningful and kind of plausible, but still false, as is proven in the accepted answer. – Mo B. Dec 27 '20 at 21:21
  • @DavidEisenstat I agree that this answer is incorrect, but it's not due to a misunderstanding of the big O notation. Technically speaking, it would be possible to interpret the OP's ambiguously phrased question in such a way that the argument of this answer is valid. One could even argue it's the correct interpretation when the phrasing of the question is taken absolutely literally. But it's clearly not the *intended* meaning of the claim. So the error in this answer lies in the misinterpretation of the claim (or the poor phrasing of the question). – Mo B. Dec 27 '20 at 21:56