This animation demonstrates how a single-pass algorithm can check if a binary tree is balanced. A tree is balanced if the height difference between left and right subtrees is at most 1 for every node. The algorithm calculates heights and checks balance simultaneously, returning the height of the subtree if it's balanced, or -1 if any part is unbalanced.
Click 'Next' to begin the visualization of the single-pass balance checking process.