r/badcode • • Jun 19 '21

typescript Check if binary tree is balanced...

Post image
221 Upvotes

44 comments sorted by

View all comments

2

u/[deleted] Jun 20 '21

Can’t you just traverse and check if any node has a single leaf node?

1

u/paulsmithkc 👨‍🏫 Jun 20 '21

You cannot. Two entire branches can be balanced in and of themselves. But if one has height 5 and the other height 3, the whole tree becomes imbalanced.

1

u/[deleted] Jun 20 '21

Ah I conflated “balanced” with “bushy” (I think that’s the word)