January 10, 2025 |11.3K Views

    Maximum width of a binary tree

      Share  2 Likes
    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/