awesome explaination.. i thought this topic was my full stop for the DSA course which i'm studying online until i came across ur video.. thank you so much.. i am ready to continue :) you got a new subscriber here #respect
Amazing explanation! Just a quick question: The time complexity of the solution shall be O(height) but should the space complexity be also O(height) => Recursive calls to search for the target node for BST?
If we have to find the inorder successor of last node i.e. 105, then can we assume that if there is no left turn happened during the search path of node 105 then there is no successor. Kindly suggest.
Thanks from your explanation, which is easy to understand, a confusion is here how to find the in order successor for 36 in the above example? please help me it is much urgent for me.
Sir what will be the output for the value 105? Here I was getting garbage value but tried to solve by means of some logic but problem is not fixed. Will you please discuss that? Thanks again.
from case 2, i do from bottom, so i start looking its successor from the key (37) than i compare it with parent and another node, final result is same 40
Yeah I was thinking the same thing. If we had a pointer where if (currentNode TAG == 0) then just return that Link which would be the Successor, i.e. the Parent
You are given a list of projects and a list of dependencies ( which is a list of pairs of projects, where the second project is dependent on the first project). All of a project's dependencies must be built before the project is. Find a build order that will allow the projects to be built. if there is no valid build order, return an error. Input: projects: a, b, c, d, e, f dependencies: (a,d), (f,b), (b,d), (f,a), (d,c) Output: f, e, a, b, d, c
Hi vevekanand, thanks for such a wonderful explanation. You mentioned that tree cannot be reversely traversed, means backtracking. But we can achieve the same using recursion. Please let me know your thoughts on that.
sir upload an video on dynamic problem;- Given arrival and departure times of all trains that reach a railway station, find the minimum number of platforms required for the railway station so that no train waits.
IHi Thank you very much for the video. It was very nice explaination. would you be able to post the code? I coded based on your explaination . 19/24 testcases are passing. Here is my code. public TreeNode inorderSuccessor(TreeNode root, TreeNode p) { if (root == null || (root.left == null && root.right == null)) { return null; } successor = null; prev = null; prev = findP(root, p); System.out.print(" p is " + p.val); // System.out.print("p.right val is " + p.right.val); if (p.right != null) { // min in the right subtree successor = minNode(root.right, p); } else { successor = findSucc(root, p); } return successor; } private TreeNode findP(TreeNode root, TreeNode p) { if (root == null || root.val == p.val) { prev = root; if(prev!=null){ r=prev.right; } return prev; } findP(root.left, p); if (root.val == p.val) { prev = root; if(prev!=null){ r=prev.right; } } return findP(root.right, p); } private TreeNode findSucc(TreeNode root, TreeNode p) { TreeNode s = null; while (root.val != p.val) { if (p.val < root.val) { s = root; root = root.left; } else { root = root.right; } } return s; } private TreeNode minNode(TreeNode root, TreeNode p) { if (root != null && root.left != null) { while (root.left != null) { root = root.left; } } return root; }
The way you just explain everything 20 times over again is amazing. It really engraves the content into my mind. Great video!
I didn't understand this until i watched the video. so true! lol
Probably the only explanation on TH-cam that is perfectly clear. Thank you my friend!
I can't explain how valuable this video is. Thank you so much. Best explanation in the YT so far.
awesome explaination.. i thought this topic was my full stop for the DSA course which i'm studying online until i came across ur video.. thank you so much.. i am ready to continue :) you got a new subscriber here #respect
This is the best explanation so far on Inorder Successor. You are a great teacher. Thanks a ton!! :)
Best explanation ever.... All your videos are lucid and to the point. Keep it up... Thank you
only explanation in youtube covering all the cases👍
This is the best explanation . Awesome!! I wish all teachers were this good India would have been going greats
What an explanation!! This should how professors teach teach their students. Keep it up! Thanks for uploading this well explained and organized video.
Very nice explanation. you are one the few guys who try to explain how to think. Awesome.
Thank you sir .Your explanations are best and i have learned a lot from you.Keep making videos like this.
Best explanation on the web. Thanks!!
Can you please do a series of algorithm questions for interview prep in a week. Sort of like things you absolutely need to know
easy and lucid way of teaching.......!thanks
sir explanation is really great
This was a really good explanation. Thanks a lot
u r amazing .. hope you land the best companies
Way better than my fucking CS class at a "top" American University. He is so composed, I love it and absorbing everything .
Very helpful, especially explanation with example
One of the best explanation
Thank you, Vivekanand! We appreciate you!
My pleasure
very nice explaining sir....You rocked
BEST explanation I've ever seen
Thank you, this was the best material on the topic
Thank you very much for the great explanation in all your videos..keep going
Best explanation as always. Keep it up 👍
very great explanations sir
hi sir, can you please make more algorithms videos on trees, linked list, graphs, and some other important algorithms for interviews
Thanks a lot for explaining so beautifully.
Explanation work is done well but the boundary case if we have to find successor of maximum node in tree will not be handled by this algo
Amazing explanation, That was a tough one :)
Amazing explanation!
Just a quick question:
The time complexity of the solution shall be O(height) but should the space complexity be also O(height) => Recursive calls to search for the target node for BST?
sir what if the user given a node which is a leaf node what will be the algo for this condition??
Great Explanation. Respect!
what about the case where target is 105? how to check if that is the last node of the tree?
If you never find a node that is a left child, then there is no successor.
This means the node started with is the largest node in the tree.
awesome Sirji!
You are the best 🍁
this video honestly deserves like
best video i ever seen.....
What if inorder succesor does not exist, suppose given node is root node and there is no right subtree for it.
If we have to find the inorder successor of last node i.e. 105, then can we assume that if there is no left turn happened during the search path of node 105 then there is no successor. Kindly suggest.
Yes there is no successor for 105
Thanks from your explanation, which is easy to understand, a confusion is here how to find the in order successor for 36 in the above example? please help me it is much urgent for me.
Sir what will be the output for the value 105? Here I was getting garbage value but tried to solve by means of some logic but problem is not fixed. Will you please discuss that? Thanks again.
It should be null. Perhaps if the node is the maximum node in a bst then its successor will always be a null.
nice explanation. thank you.
Awesome explanation ! Thanks !
from case 2, i do from bottom, so i start looking its successor from the key (37) than i compare it with parent and another node, final result is same 40
Excellent Explanation
awesome explaination
Vivekanand sir would you please explain the time complexity of the algorithm also?
If we had a parent pointer could we just do if(current node == left child of parent) then return that for case 2?
Yeah I was thinking the same thing. If we had a pointer where if (currentNode TAG == 0) then just return that Link which would be the Successor, i.e. the Parent
May be.
You are given a list of projects and a list of dependencies ( which is a list of pairs of projects, where the second project is dependent on the first project). All of a project's dependencies must be built before the project is. Find a build order that will allow the projects to be built. if there is no valid build order, return an error.
Input:
projects: a, b, c, d, e, f
dependencies: (a,d), (f,b), (b,d), (f,a), (d,c)
Output: f, e, a, b, d, c
Read about Topological Sorting using Stack, that would help you.
Excellent, thank you.
awesome sir
Not a single dislike! Awesome!
Hi vevekanand, thanks for such a wonderful explanation. You mentioned that tree cannot be reversely traversed, means backtracking. But we can achieve the same using recursion. Please let me know your thoughts on that.
dhawal patel lol they r same
Sir, please use duster, rubbing the marker ink through your fingers may cause skin problems.
HI Vivek,
Can you please post the code for deletion of a node from BST?
sir upload an video on dynamic problem;- Given arrival and departure times of all trains that reach a railway station, find the minimum number of platforms required for the railway station so that no train waits.
very good explanation
Like array tutorial do have any tutorial for Strings related question
Hi Vivekananda,
Can you please upload the video for finding all nodes at a distance k from a target node
Run BFS it gives you the shortest natural distance from starting node, keep track of the distance, you can use DFS too but BFS will be easier
HIMANSHU CHHABRA thanks . I will try it out.
Nice explanation!!
What will be the inorder successor for 105 in this example?
Successor means the next higher value right? so for 105 there is no successor as this is the max value of that tree.
if store pointer is null that means there was no left turns made, thus no inorder successor.
10:19
Great Explanation tho. (Y)
Thanks 🙏 😊
Thank u sir ♥️
can I achieve this through recursion
what about if it is an alphabets
Thank u sir
Thank you 😀😁
Can you please show how to convert roman number to number was a interview question..
please make video on red-black tree.
nice explanation
can we also use stack ?
yeah sure...but without using stack u r able to solve this....then why do u want to use stack..
Many Thanks
you can ask me in comments, and I will never reply.. because he has not replied to any of the comment.
I would appreciate if you can show your code for case 2. Thank you.
yes sure...i have written the code on board ...but did not explain...will make a video on code explanation
can you do video on
splay trees
16:30 also say that first untraversed parent
Thanks sir
Sir is video ka code kha milegea
Muje code cahhiye sir pls
thanks
bhai ek request hai apse please hindi me bol liya kijiye..english teak se explain nai kr pa rhe ho ap
Gem.
Where is The Source Code
This Logic is Not Working in all Cases
wuah😃
sir upload graph
are you single? ;)
IHi Thank you very much for the video. It was very nice explaination. would you be able to post the code? I coded based on your explaination . 19/24 testcases are passing.
Here is my code.
public TreeNode inorderSuccessor(TreeNode root, TreeNode p) {
if (root == null || (root.left == null && root.right == null)) {
return null;
}
successor = null;
prev = null;
prev = findP(root, p);
System.out.print(" p is " + p.val);
// System.out.print("p.right val is " + p.right.val);
if (p.right != null) {
// min in the right subtree
successor = minNode(root.right, p);
} else {
successor = findSucc(root, p);
}
return successor;
}
private TreeNode findP(TreeNode root, TreeNode p) {
if (root == null || root.val == p.val) {
prev = root;
if(prev!=null){
r=prev.right;
}
return prev;
}
findP(root.left, p);
if (root.val == p.val) {
prev = root;
if(prev!=null){
r=prev.right;
}
}
return findP(root.right, p);
}
private TreeNode findSucc(TreeNode root, TreeNode p) {
TreeNode s = null;
while (root.val != p.val) {
if (p.val < root.val) {
s = root;
root = root.left;
} else {
root = root.right;
}
}
return s;
}
private TreeNode minNode(TreeNode root, TreeNode p) {
if (root != null && root.left != null) {
while (root.left != null) {
root = root.left;
}
}
return root;
}
very good explanation