Grokking Tree Coding Patterns for Interviews
Ask Author
Back to course home

0% completed

Vote For New Content
Bruno Ely
Example 2 seems wrong?

Bruno Ely

Jan 18, 2024

1 / \ 2 2 / \ 3 3 / \ / \ 4 4 4 4

In example 2, the height difference for the two nodes with value "2" is 2. Their inner subtree has height 1, and their outer subtree has height 3.

9

0

Comments
Comments
J
Jimmy 2 years ago

I agree.

Design Gurus
Design Gurus2 years ago

Both nodes with value "2" have height 2. As they both have same height, hence their height difference is 0.

Did we understand your question correctly?

Tuấn Trần
Tuấn Trần2 years ago

It states that: "A binary tree is considered height-balanced if, for each node, the difference in height between its left and right subtrees is no more than one".

If I understand correctly, it means that in a balanced tree, I can pick a node randomly, then: abs(left_he...