0 votes 0 votes A node is height balanced if difference between height of left subtree and right subtree is either -1 , 0 or 1 , so how to count such nodes , without maintaining any extra field in the node except for left and right child pointers . radha gogia asked Apr 7, 2016 radha gogia 566 views answer comment Share Follow See all 0 reply Please log in or register to add a comment.
Best answer 3 votes 3 votes Do a post order traversal of the tree. First we traverse the left subtree - let it return the height of it - say n1. Traverse the right subtree - let it return its height - say n2. Now, if |n1 - n2| <= 1 increment a global counter. Tree traversal is $O(n)$ and so we are done. Arjun answered Apr 7, 2016 • selected Apr 7, 2016 by radha gogia Arjun comment Share Follow See all 0 reply Please log in or register to add a comment.