Find width of binary tree

Find width of binary tree.

The width of a tree is maximum number of nodes at any level (or depth) in tree.

Solution:

  1. Recursive
  2. BFS using queue

Source Code:
Github: BinaryTreeWidthFinder.java


Output:

                         
               1                               
              / \               
             /   \              
            /     \             
           /       \            
          /         \           
         /           \          
        /             \         
       /               \        
       2               3               
      / \             / \       
     /   \           /   \      
    /     \         /     \     
   /       \       /       \    
   4       5       6       7       
  /       /                     
 /       /                      
 8       6                       
          \                     
          7                     
                                                                
Width is : 4
Width is (non-recursive): 4
       1               
      / \       
     /   \      
    /     \     
   /       \    
   2       3       
  /         \   
 /           \  
 4           5   
/ \             
6 7             
                                


Width is : 2
Width is (non-recursive): 2
Author: Hrishikesh Mishra