Find the maximum width of a binary tree

Objective: Given a binary Tree, write an algorithm to find the maximum width.

Note: Maximum width of a tree is nothing but the Max(nodes at each level).

Input: A Binary Tree

Output: Maximum width of a given tree.

Example:

Maximum width of a given tree

Approach:

The solution of this problem is very simple, Do level order traversal and in recursive calls count the number of nodes at each level and keep track of Max of them and at the end return the max.

Read this solution ” Level Order Traversal, Print each level in separate line” and implement the above approach.

Complete Code:

Output:

Maximum Width of a binary Tree is : 4

__________________________________________________
Top Companies Interview Questions..-

GoogleMicrosoftAmazonFacebookmore..

If you find anything incorrect or you feel that there is any better approach to solve the above problem, please write comment.
__________________________________________________

You may also like...

1 Response

  1. Aman Rustagi says:

    Here is an alternate approach without using Queue data structure. It uses recursion to traverse binary tree and count width of each level.
    http://www.techcrashcourse.com/2016/06/program-to-find-maximum-width-of-binary-tree.html
    http://www.techcrashcourse.com/2016/06/data-structures-programming.html

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: