Some of the best things about your video, 1. your slow explanation. 2. code walk through 3. Complete explanation with lots of examples. Thank you.
@parthobala72516 жыл бұрын
agree
@tanmayagarwal85133 жыл бұрын
OKK .. lets just appreciate his innocent smile!
@vardaanbajaj31816 жыл бұрын
This topic has confused me since 2 days. This is the best explanation I've found. Thank you sir :) Cleared all my doubts :)
@sjwang38923 жыл бұрын
Absolutely love the clear explanation and walkthrough. Thank you!
@sagarmalshankhala68262 жыл бұрын
Sir ji, apka teaching ka FAN ho gya hu me to .. love you. Some of the best things about your video, 1. your slow explanation. 2. code walk through 3. Complete explanation with lots of examples.
@ivantishchenko46864 жыл бұрын
The author is a genius. Thank you very much!
@___vandanagupta___ Жыл бұрын
i was not able to understand this question's solution from any other video but your simple explanation worked and i will never forget this solution again, thanks so much sir!
@uncletom3215 жыл бұрын
I rarely subscribe to channels, but I did for yours because of how great your teaching method is. It has really helped me better understand data structures and algorithms. Thanks!
@sushmanthnatha40194 жыл бұрын
Sir, I have watched many other people videos but your's are simply crystal clear
@aishwaryadwani93655 жыл бұрын
Sir one thing i must say here , your videos and explanations are out of the box. Very easily anyone can get it. Thanks allot.
@Dizzydizzydizzy72 жыл бұрын
usually i have a hard and long time understanding these kinds of videos, but your videos are so clear I feel like even a toddler can understand
@bajracha5 жыл бұрын
Thank you so much for such a clear explanation. Your explanation not only taught me how to understand walking through the algorithm but it actually taught me how to think about a solution and how to approach the solution. Thanks again.
@sharmapeeyoosh2 жыл бұрын
Hello, Thanks for explaining so well, In your logic for finding out LCA works fine if both the nodes are present and both the nodes are part of different sub tree. Two situation does not handle in this code. 1) if either of the node is not present in tree itself 2) if second node is part of subtree of first node. for exm, P and L nodes. If user enters these two nodes then this algorithm will not work. Solution algorithm: 1) Both the nodes must present in tree otherwise print error and return. 2) if left and right returns non NULL, this is LCA. Print LCA and return NULL. 3) if second node is in subtree of first node then only first node we will return till root node. in such case main function shall have a piece of code, if final return is non NULL then this is the LCA, print LCA. I can post the code if someone needs. thanks
@deliveringIdeas2 жыл бұрын
Sure please post
@user-uh4be8ci7i2 жыл бұрын
You are the best teacher sir thank you so much for all this solutions
@YSSP46 жыл бұрын
Awesome video. Your explanations are simple and clear to understand. Please keep up the good work. For others, just like me if you are bothered about corner case where one of the element is not present in the tree, then try postorder traversal instead of inorder traversal so that you look in to both left and right nodes before coming to root node.
@sandeepnallala483 жыл бұрын
thanks for making things clear and simpler sir
@adaz27244 жыл бұрын
I love this guy, very clear explanation !!!
@ishanpand3y4 жыл бұрын
Sir, I think this is preorder traversal. Because in inorder traversal first we go left then node then right, while in preorder traversal first we go node then left and then right.
@marioburgos86564 жыл бұрын
I agree
@cripz42034 жыл бұрын
isnt it postorder as we are processing what to return after left and right.
@utkarshsingh44564 жыл бұрын
@@cripz4203 postorder hai bhai, you are right.
@bismeetsingh3523 жыл бұрын
It is inorder since we go leftmost,root and then right
@rohitjadhav5123 жыл бұрын
No...its postorder.
@harshshukla33583 жыл бұрын
sir this is a very good explanation, just one point that you should have told that we are taking the assumption that both the nodes exist in the tree
@daspradeep6 жыл бұрын
good explanations, got tripped by the edge case a bit because this assumes both nodes to be present in the tree, which is fine i guess. In case one of the nodes is not there then it fails.
@shashwatagrawal84125 жыл бұрын
Amazing explanation. Please make more videos on Algorithms.
@RavinderSingh-nh6th5 жыл бұрын
i dont know how to praise you. i have less words to appreciate you..
@bogdandumitrescu89873 жыл бұрын
No need for "else". Great code walkthrough and explanation !
@vivekanandkhyade3 жыл бұрын
Much appreciated!
@RamKumar-kz8gg3 жыл бұрын
can you explain it please
@hritikagarwal76764 жыл бұрын
It would be far better if you also explain the intuition to this solution. Knowing the algorithm makes half of the work but knowing what led to this algorithm will make the solution video totally worthy.
@shwetadk19865 жыл бұрын
You are simply amazing !. Keep the good work and spread the knowledge
@dipakkumarsinha58114 жыл бұрын
Bahut badhiya sir .... Maja a Gaya sir
@sampathmethuku74285 жыл бұрын
very good explanation , but I think if the any one node either p or q does not exists then your code will fail, we expect to return null as one node is not present in tree. but your code returns the existing value.
@shadesofspice53154 жыл бұрын
Clear explanation. Easy to understand
@anty_075 жыл бұрын
A somewhat concise solution which uses the property of BST - LCA's value WILL fall between the the two given nodes. SO you keep going left from root till both the nodes values are less than current node , and keep going right till both value are greater than current value. Below is the code. while(root.data < v1 && root.data < v2){ root = root.right; } while(root.data > v2 && root.data > v1){ root=root.left; } return root;
@vm16625 жыл бұрын
Yes this works perfectly for Binary Search Tree but I guess the code explained in the video is for Binary Tree :)
@andreeachirita98012 жыл бұрын
really good method of explaining!!
@nishantprajapati71665 жыл бұрын
Awesome explanation, great sir.
@gouravsharma27556 жыл бұрын
Very good explanation.I liked the reasoning in your videos.
@4yt1584 жыл бұрын
Your explanation is awesome bro! Thank you! :)
@danielshalam22586 жыл бұрын
finally i understand how it works ! thank you very much !
@krishnavasani263 жыл бұрын
Awesome video. Great explanation, keep up the good work sir!!
@abhishekkumargupta30434 жыл бұрын
This man is awesome. Thank you.
@user-nd2lf7ss4x2 жыл бұрын
so clear explanation!
@angadrajsingh43114 жыл бұрын
Sir amazing explanation
@rishabhjain45463 жыл бұрын
Great Video. Thank you sir. What happens in the case when there is only one value present in the tree, and the other value is not. In that case, the algorithm is not working.
@pi_by_22242 жыл бұрын
try this approach struct TreeNode* lowestCommonAncestor(struct TreeNode* root, struct TreeNode* p, struct TreeNode* q) { if (p->valval && q->valval) return lowestCommonAncestor(root->left,p,q); if (p->val>root->val && q->val>root->val) return lowestCommonAncestor(root->right,p,q); return root; }
@kartikaygoel30424 жыл бұрын
Great Video... PS-: can watch it at 4x comfortably
@alokdeshpande55174 жыл бұрын
Excellent explanation 👍
@HoanNguyen-fc8vb3 жыл бұрын
Thank you for your tutorial. You are one of the best so far. For the if(left !=null && right = null) return root. Is that right or (right !=null) .Please explain. Thank you very much.
@beaglesnlove5802 жыл бұрын
Ur a amazing teacher
@vivekanandkhyade2 жыл бұрын
👍👍
@vishalplayzz25802 жыл бұрын
@@vivekanandkhyade sir pls continue this lectures
@ayushmishra33883 жыл бұрын
I think so this algorithm will fail when there are multiple occurrences of n1 and n2, @8:06 pause the video see the tree, and replace the following nodes: *h with m, i with r, e with r.* after first finding m and r, node "D" becomes LCA and returns itself to "B", then "B" checks on its right, it finds "R", now on left of "B" we have "D" as LCA and on right of "B" we have "R" as LCA, so it will return "B" as LCA which is wrong, LCA Should have been "D" only.
@GauravKawatrakir3 жыл бұрын
This solution not work when one of the two nodes is found and not the second one. So its return the founded node.
@Sudarshansridhar4 жыл бұрын
what if the one of node given to find lca is not present in the tree? i think this solution holds good for both values are present. (if i am not wrong)
@swj_694204 жыл бұрын
Can you please tell how is this inorder? Shouldn't it be preorder
@aparna123pathak6 жыл бұрын
No doubt in awesomeness of explanation!!
@PIYUSH-lz1zq2 жыл бұрын
DAMM !!! ABSOLUTLY SPOT ON
@thecreative91024 жыл бұрын
Thank you so much for great explanation
@payalsagar18084 жыл бұрын
the best!☺
@rohinirt63625 жыл бұрын
Thank you so much for all your video sir...
@1388tushr5 жыл бұрын
How about LCA of "f" and "j"? I think once the code hits "f", it will return "f", it won't go to its child.
@lavishgarg42744 жыл бұрын
yes and that too should be the answer
@natesh16 жыл бұрын
Awesome vids, can u please consider categorizing ur vids into playlists, for new watchers it helps a lot, otherwise they would have to keep scrolling all ur vids.
@lokeshnegi50514 жыл бұрын
well explained..
@chetannikam81293 жыл бұрын
nice video.............................
@nikhilkumarmishra12255 жыл бұрын
You are godsent, thanks a lot!
@GROW_WITH_GBT3 жыл бұрын
Thanku ji
@7Critics5 жыл бұрын
Great explanation!
@unboxingzindagi99724 жыл бұрын
Love you bro. You are so real!!
@sayalishelke95974 жыл бұрын
Best explanantion :) .Subscribed
@neetisharma37685 жыл бұрын
Liked and subscribed :) Thank u for explaination
@anupkmr035 жыл бұрын
Nice explanation Thank you.
@vivekmit5 жыл бұрын
Good explanation
@jagritbhupal58364 жыл бұрын
Thank you
@rajnikushwaha14596 жыл бұрын
sir your video is really awesome
@VenkatGonu4 жыл бұрын
code doesn't work if one of the node is not present, ideally it should return null but it returns the other node which is found
@borisa69527 жыл бұрын
Thank you for the explanations. I would like to know how to compute and write the algorithm of the "distance between the node e and node i" in this binary tree.
@borisa69527 жыл бұрын
I mean how to write the algorithm between two nodes (not root node) in a binary. The example with nodes e and i would be useful for me. Thank you in advance.
@arpitverma80604 жыл бұрын
VERY WELL EXPLAINED||
@radhakantaghosh72956 жыл бұрын
Hi, Does this method will work for "d" and "h" ? ..........what i am thinking is once execution hit "d" then, it will return that node and will never visit "h".
@raniajay04105 жыл бұрын
whats the use of visiting h if we have already found d which is LCA.
@1388tushr5 жыл бұрын
@@raniajay0410 then how will you know whether "h" exists or not?
@abcd12359115 жыл бұрын
@@1388tushr Exactly. If one of the nodes is not present this algorithm will return the other node which is present
@RohanSingh-bl5ho5 жыл бұрын
@@abcd1235911 this what i was thinking while i was watching this video, this algo is not completely correct
@kabboghosh18535 жыл бұрын
best teacher
@TS-ku2lg4 жыл бұрын
Thank you so much sir!
@sumitkumar-wp4xd7 жыл бұрын
great job sir
@tassda27874 жыл бұрын
merci monsieur
@sunnyjain6306 жыл бұрын
i think u have used preorder traversal!!
@sakshamagarwal68525 жыл бұрын
good explanation sir, thanks :)
@pradeepsingh-cg8iv4 жыл бұрын
Thanks bro
@jamesqiu67157 жыл бұрын
you used postorder traversal ... I think
@samaryadav72087 жыл бұрын
yeah because he is returning after checking the values of both the children
@gyanasahu10066 жыл бұрын
It is Inorder traversal, as we first check with the current node and return if it is equal to either one. If not equal we expand search to left subtree and right subtree
@badsum6 жыл бұрын
Actual result comparison happens after both, left and right, return. It is post order. Also, if checking current node first for the result comparison, it should be pre-order, not in-order.
@charismatic15164 жыл бұрын
@@badsum Actually, there is both pre and post happening. However, in terms of logic, we check for LCA condition for the current node before checking it left and right subtrees, hence pre. We also do some checking/processing after the children processing. Similar example is when we want to do a sum of all root to leaf paths. In the recursive function, we first add node val to sum so far, then check if we reached a leaf (pre) then return sum, else get sums from left and right child, then add and return those sums (some post).
@charismatic15164 жыл бұрын
@@gyanasahu1006 You meant pre, not in
@abhishekkarn89186 жыл бұрын
this is preorder traversal na sir?
@harirahul77033 жыл бұрын
great explanation but i think this is pre order traversal
@oneworldofstem77244 жыл бұрын
I wonder when you first encounter this question, how do you figure out the possible steps for getting the answer? I am having trouble of algorithm questions recently. Very hard for me to think of the answer
@gauravburjwal.984 жыл бұрын
same lol
@AshokBathini7 жыл бұрын
If one of the nodes p or q does not exist in the Binary Tree, this function will still return the node which is found, but it should have returned NULL. Am I right?
@vivekanandkhyade7 жыл бұрын
yes Ashok , u r right.....Due to the restriction of space on board , I have just focused on the main condition.....in the code we can modify for this corner condition.....Thanks for helping me get better...!
@AshokBathini7 жыл бұрын
It's just a corner case, but otherwise you've explained it very well..good job!
@ayushthakur7334 жыл бұрын
Explain it for (j,c).... 🤨
@adityachauhan11823 жыл бұрын
this solution will not work in case if B==root->node ans c is not present
@ricardosmith37525 жыл бұрын
What if one of the element is in the left branch of other ?
@SaurabhSingh-ch6nc5 жыл бұрын
Love it ..!
@prajakta_patil5 жыл бұрын
Thank u
@mdsaif46967 жыл бұрын
In my interview, the question asked me to return int value.. not node value.. this method just messed.up. pls explain what to do if the function demands returning int value
@ShivangiSingh-wc3gk6 жыл бұрын
You should have just returned node.value and kept something like -1 for a case where you dont find the node
@ShubhamKumar-oh3jt5 жыл бұрын
when you are returning the value use .data or .key with the calling function
@ayushthakur7334 жыл бұрын
What if the root node is one of the two node ??
@jingli21683 жыл бұрын
Should be pre-order instead of in-order.
@SaurabhSingh-ch6nc4 жыл бұрын
this is how the DSA faculty looks like!
@adityaojha27013 жыл бұрын
It's good
@ruchirai57754 жыл бұрын
nice !!
@suryajena15752 жыл бұрын
This won't work when one of the two nodes is not found.
@TechnicalBaniya7 жыл бұрын
sir for node k the ancestors are f,c,a and the ancestors of node f are c,a then the common ancestor should be c of nodes k and f but you said the common ancestor is f ?
@vivekanandkhyade7 жыл бұрын
the lowest common ancestor for parent and its child is the parent itself. I am sorry i have not explained this in the video. I will reply tomorrow again with a more convincing proof. Thanks.
@hellochii16755 жыл бұрын
10:08, I think you want to write "a", but not "LCA" ?
@bigjforever7 жыл бұрын
good. but a little bit slow. I need to see ur vdos at 2x speed
@ridimamittal40644 жыл бұрын
make more videos plzzzzzzzzzzz :(
@zeref64375 жыл бұрын
if LCA is not present it will return wrong answer.