[+2] [-2]
7 3
/ \ / \
[+2] 6 9 [0] [0] 2 5 [-2]
/ \
[+1] 3 9 [-1]
/ \
[0] 1 10 [0]
(Tree 1) (Tree 2)
It represents the equilibrium argument of each node in a binary tree. I don't understand why you can get the equilibrium argument by subtracting the height of the right subtree from the height of the left subtree.
Doesn't the level of the tree start with 1 from the root node? Does the leaf node start with 1 only when calculating the equilibrium argument?
algorithm
The height in the tree is also expressed as Depth and Level, which means that it increases by 1 each time it goes down from the reference node to the child node. In this case, child can be left/right. So you can think of it as the depth of the tree.
Since the leaf node has no child, the depth (height) of both subtrees is of course zero.
If you look at the (6) node in (1), the depth from the left subtree to (1) is 2. Because the right side is zero, the equilibrium factor is +2. Even if the subtree is divided into several branches, you can look at it based on the deepest node.
If you look at the root node in (Tree 1), the depth from the left subtree to (1) is 3, and the depth from the right subtree to (9) is 1, so 3 - 1 = 2 is the equilibrium factor.
539 Uncaught (inpromise) Error on Electron: An object could not be cloned
547 Who developed the "avformat-59.dll" that comes with FFmpeg?
723 When building Fast API+Uvicorn environment with PyInstaller, console=False results in an error
542 Unable to install versioned in Google Colab
548 rails db:create error: Could not find mysql2-0.5.4 in any of the sources
© 2024 OneMinuteCode. All rights reserved.