Тёмный

Diameter of Binary Tree (LeetCode 543) | Full Solution with Examples | Study Algorithms 

Nikhil Lohia
Подписаться 48 тыс.
Просмотров 20 тыс.
50% 1

Опубликовано:

 

26 сен 2024

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 27   
@pranavbhat92
@pranavbhat92 7 месяцев назад
Very informative! Thank you :)
@replymadhug
@replymadhug 2 месяца назад
Amazing explaination
@ganeshjaggineni4097
@ganeshjaggineni4097 2 месяца назад
NICE SUPER EXCELLENT MOTIVATED
@subee128
@subee128 9 месяцев назад
Thanks
@shubhamgupta48
@shubhamgupta48 7 месяцев назад
What do you mean when you refer the depth of the node around 3:59, For me the depth means, The depth of a node in a binary tree refers to the number of edges in the path from the root node of the tree to that specific node. In other words, it represents how far down the node is from the root,, can you please elaborate that dept part.
@nikoo28
@nikoo28 7 месяцев назад
Check out this video: ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-o2LEC2NEVuk.html
@shubhamgupta48
@shubhamgupta48 6 месяцев назад
@@nikoo28 Ok thanks. but then how is the depth of leaf nodes 2, 1, 6, 0, 1 is 1 and then similarly for 7, 5 is 2 I am little lost there. Or may be I am understanding here incorrectly. Pls explain .
@nikoo28
@nikoo28 6 месяцев назад
I see your confusion...actually, depth of a node relative to tree, and depth of a need relative to a node are different. In this particular problem, our frame of reference is the parent node to leaf nodes. unfortunately, there is not generic definition for depth of a node.
@ajayrajput256
@ajayrajput256 3 года назад
Sir please continue for tree and graph tutorial also 😊
@nikoo28
@nikoo28 3 года назад
Sure…but it will be a while. I am trying to lay the foundations first :)
@ajayrajput256
@ajayrajput256 3 года назад
@@nikoo28 thanks 🙏
@nikoo28
@nikoo28 7 месяцев назад
The complete playlist on graphs is now available: ru-vid.com/group/PLFdAYMIVJQHNFJQt2eWA9Sx3R5eF32WPn
@NiteshKumar-hl6er
@NiteshKumar-hl6er 6 месяцев назад
DFS seems so much more harder than BFS, any idea on how i can improve on it?
@nikoo28
@nikoo28 6 месяцев назад
DFS and BFS are literally the same...one uses a stack, other uses a queue. Watch my videos on BFS and DFS...and this concept will be clear for the rest of your life :)
@unemployedcse3514
@unemployedcse3514 24 дня назад
actually depth word used explanation is misleading , it's actually maximum level the node is from leaf default starts with one , depth is the number of edges from leaf node to root
@madhumithraravi9087
@madhumithraravi9087 3 года назад
You make things so easy, Can you share us Tree and graphs related programs and theories, BFS and DFS ? , thank you,
@nikoo28
@nikoo28 3 года назад
thanks for the appreciation. Yep, I am working on those algorithms. You can expect to start seeing tree videos in my upcoming 3-4 videos. :)
@madhumithraravi9087
@madhumithraravi9087 3 года назад
@@nikoo28 thank you
@madhumithraravi9087
@madhumithraravi9087 3 года назад
Will this solution works if the tree has duplicates?
@nikoo28
@nikoo28 7 месяцев назад
The complete playlist on graphs is now available: ru-vid.com/group/PLFdAYMIVJQHNFJQt2eWA9Sx3R5eF32WPn
@pranaym143
@pranaym143 4 года назад
Cool thumbnail
@madhumithraravi9087
@madhumithraravi9087 3 года назад
Will this solution work out if the tree has duplicates?
@nikoo28
@nikoo28 3 года назад
Yes, the iterative method will work
@Nainalarenukadevi9196-dh8rz
@Nainalarenukadevi9196-dh8rz 4 месяца назад
can anyone provide this code in python??
@harshabapatla4130
@harshabapatla4130 3 месяца назад
def diameterOfBinaryTree(self, root: Optional[TreeNode]) -> int: stack = [] maps = {} diameter = 0 if root: stack.append(root) while stack: node = stack[-1] if node.left and node.left not in maps: stack.append(node.left) elif node.right and node.right not in maps: stack.append(node.right) else: stack.pop() left = maps.get(node.left, 0) right = maps.get(node.right, 0) maps[node] = 1 + max(left, right) diameter = max(diameter, left + right) return diameter
@pedrohenriqueleite9382
@pedrohenriqueleite9382 Год назад
I still don't understand how stack works
@nikoo28
@nikoo28 Год назад
Watch my video on stack data structure.
Далее
Diameter of a Binary Tree - Leetcode 543 - Python
15:34
Diameter of a Binary Tree (Code/ Algorithm)
17:15
Просмотров 94 тыс.
Diameter of a binary tree | Leetcode #543
13:31
Просмотров 60 тыс.