Find width of binary tree.
The width of a tree is maximum number of nodes at any level (or depth) in tree.
Solution:
- Recursive
- 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