it will be good if u upload the brute force solution also sir. Thanks a lot
@NiteshKumar-hl6er8 ай бұрын
DFS seems so much more harder than BFS, any idea on how i can improve on it?
@nikoo288 ай бұрын
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 :)
@replymadhug4 ай бұрын
Amazing explaination
@shubhamgupta489 ай бұрын
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.
@nikoo288 ай бұрын
Check out this video: kzbin.info/www/bejne/pWOvdnZog6qJq80
@shubhamgupta488 ай бұрын
@@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 .
@nikoo288 ай бұрын
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.
@ganeshjaggineni40974 ай бұрын
NICE SUPER EXCELLENT MOTIVATED
@subee12811 ай бұрын
Thanks
@ajayrajput2563 жыл бұрын
Sir please continue for tree and graph tutorial also 😊
@nikoo283 жыл бұрын
Sure…but it will be a while. I am trying to lay the foundations first :)
@ajayrajput2563 жыл бұрын
@@nikoo28 thanks 🙏
@nikoo289 ай бұрын
The complete playlist on graphs is now available: kzbin.info/aero/PLFdAYMIVJQHNFJQt2eWA9Sx3R5eF32WPn
@pranavbhat928 ай бұрын
Very informative! Thank you :)
@unemployedcse35142 ай бұрын
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
@madhumithraravi90873 жыл бұрын
You make things so easy, Can you share us Tree and graphs related programs and theories, BFS and DFS ? , thank you,
@nikoo283 жыл бұрын
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. :)
@madhumithraravi90873 жыл бұрын
@@nikoo28 thank you
@madhumithraravi90873 жыл бұрын
Will this solution works if the tree has duplicates?
@nikoo289 ай бұрын
The complete playlist on graphs is now available: kzbin.info/aero/PLFdAYMIVJQHNFJQt2eWA9Sx3R5eF32WPn
@pranaym1434 жыл бұрын
Cool thumbnail
@madhumithraravi90873 жыл бұрын
Will this solution work out if the tree has duplicates?
@nikoo283 жыл бұрын
Yes, the iterative method will work
@Nainalarenukadevi9196-dh8rz6 ай бұрын
can anyone provide this code in python??
@harshabapatla41305 ай бұрын
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