This has to be the simplest explanation on youtube. The idea of taking an idea like DFS or BFS, and showing example after example of it being used with increasing complexity is the best way to learn. I bought your course on Udemy just to support you.
u can for example add a boolean, initialize it to true and add it as a condition in the while loop, if we reach the else condition(path1[i]path2[j])u can set it to false to exit the loop, hope i helped!
Any node in a binary tree is a root of a smaller tree, so we can just combine the search() and the get_path() function, we search for the source node, then we call get path on it once we find it
For lca there's no need to make 2 paths, here's a simple dfs that does it: def lca(root, val1, val2): if root in (val1, val2): return root left = root.left.lca(val1, val2) if root.left else None right = root.right.lca(val1, val2) if root.right else None return root if left and right else (left or right)
In 5 minutes there's more value in this video than in hours of other tutorials!
This has to be the simplest explanation on youtube. The idea of taking an idea like DFS or BFS, and showing example after example of it being used with increasing complexity is the best way to learn. I bought your course on Udemy just to support you.
Wow, thanks a lot!
Thank you for your great explanation and beautiful illustration. You taught me a lot!
Brother you are a saviour...please do more videos like this only on all data structures, and common algorithms which can solve many questions.
Your amazing tutorials helped me immensely, please keep them coming. Thank you!!!
You're welcome!
Can you make a video for tree problems where path doesn't necessarily pass through root? I struggle here thanks!
Give me an example!
@@insidecode Longest path in a tree.
Great explanation, one stop point for conceptual understanding of various path related problems
Could you please make a video on construction of trees using various given traversals like preorder,postorder etc?
That would be really helpful
It would be interesting yes
Nice explanation. Animations are 🔥
i am glad that found your channel
for the Lca function basically in exam we can't use break; so what can i replace it with? if the path doesnt match?
u can for example add a boolean, initialize it to true and add it as a condition in the while loop, if we reach the else condition(path1[i]path2[j])u can set it to false to exit the loop, hope i helped!
The code used for getting path array is returning empty array.., can you please check again
THE BEST ! "after me"
I am wondering and trying to figure out What is the answer to the exercise 3:24 with just using dfs func with an additional parameter val2
Any node in a binary tree is a root of a smaller tree, so we can just combine the search() and the get_path() function, we search for the source node, then we call get path on it once we find it
All you just need to do is to search for the source node and make it the root of the tree.
thanks
I am ur new subscriber 🤗
Great
Ur a hero
good content btw !
Amazing
For lca there's no need to make 2 paths, here's a simple dfs that does it:
def lca(root, val1, val2):
if root in (val1, val2):
return root
left = root.left.lca(val1, val2) if root.left else None
right = root.right.lca(val1, val2) if root.right else None
return root if left and right else (left or right)
L engineeeeer yah !
amazing