# Please tell me how this recursion code works at ```is_balanced(node.left)```

``````def is_balanced(node):
if node is None:
return True, 0
balanced_l, height_l = is_balanced(node.left)
balanced_r, height_r = is_balanced(node.right)
balanced = balanced_l and balanced_r and abs(height_l - height_r) <=1
height = 1 + max(height_l, height_r)
return balanced, height

is_balanced(tree)
``````

The following tree is balanced:

1 Like

Just Imagine this treeâ€¦

``````        1
/ \
2   3
``````

And try to go through the code line by lineâ€¦depth by depth and using a pencil and paper and making the recursion Stack and try to uncover the explanation by yourselfâ€¦that way youâ€™ll understand the concept more clearly

Also I have already explained the `checkbst(node)` function to you so this function would work as an exercise for youâ€¦

Also when you are done with the above treeâ€¦go for the tree you have posted and try to understand how everything worksâ€¦

Hope you will get itâ€¦Good Luckâ€¦

The best way for you to see would be to use a debugger. I recommend using Thonny IDE and learn how to use itâ€™s debugger.