Binary Tree in Java - 32: Get Maximum width of Binary Tree (Max element present in any level)

preview_player
Показать описание
Solution:
- We'll take one queue & take level & size variable & max_width
- Add element in queue from root node & keep on adding left & right in queue
- We'll check if size is greater than max_width then update the max_width
- When size is zero for a level, we'll increase level
- Add the last return max_width

Time Complexity: O(n)
Space Complexity: O(n)

Do Watch video for more info

This Problem is synonym of following problems:
Binary tree get maximum width,
Binary tree get max width,
Binary tree max width,
Binary tree maximum width,
maximum width,
max width,
Binary tree in java,

Please check video for more info:

CHECK OUT CODING SIMPLIFIED

★☆★ VIEW THE BLOG POST: ★☆★

I started my YouTube channel, Coding Simplified, during Dec of 2015.
Since then, I've published over 200+ videos.

★☆★ SUBSCRIBE TO ME ON YOUTUBE: ★☆★

★☆★ Send us mail at: ★☆★

Рекомендации по теме
Комментарии
Автор

Linkedlist does not accept the node as a parameter

dineshkumarg
Автор

sir i have done with your code which u already teaches that is spiral way of printing that is working well or not?

Indian-.TT
Автор

Correct me if i am wrong but the time complexity is O(n^2) right? i mean the algorithm is running in nested While loops.

mettudheeraj
Автор

This doesn't work if the binary tree is not complete, can you please make it generic for that case

nishilshah
join shbcf.ru