January 10, 2025 |8.3K Views

Maximum width of a binary tree

  Share  1 Like
Description
Discussion

Given a binary tree, write a function to get the maximum width of the given tree. Width of a tree is maximum of widths of all levels.

Let us consider the below example tree.  

Input:
            1
         /   \
      2      3
   /   \       \
4     5       8 
             /     \
          6        7
Output:  3
Explanation: For the above tree, 
width of level 1 is 1, 
width of level 2 is 2, 
width of level 3 is 3 
width of level 4 is 2. 
So the maximum width of the tree is 3.

Maximum width of a binary tree: https://www.geeksforgeeks.org/maximum-width-of-a-binary-tree/