View algorithms on Trees
Question: Given the root pointer to a binary tree, find the height. Input: Sample Tree (Pointer to node 1 is given). Output: 3 We discussed the recursive method to find the height of the binary tree in this post- Find the height of the binary tree The non-recursive method will definitely require the level order traversal technique. The level order traversal will traverse the above tree in following manner- 1 2, 3 4, 5 If we are able to keep a track for end of each level, we can easily …