This entire playlist is a treasure. Downloaded all the videos and created multiple copies in my PC, my external hard drive and google drive. Cannot risk it losing in case of apocalypse. And whoever you are, a big thank you. You are a GOAT.
Hi Sir, I have followed all your BST tutorials. It was very great and clear explanation. Initially I was afraid of learning BST. Now I can say I have learned BST confidently from your explanation. Thank you very much your contribution to helping programmers.
mycodeschool Your tutorials are BRILLIANT! Please do continue the series as soon as possible. Would like to see more on Trees, Graphs, Maps, Hash-tables etc.
Hi I'm Kapil, These codes for successor and predecessor seem to work fine. They keep on storing the pointer to nodes whose value is greater than (or less than) the given integer in the path of search for the integer and the latest updated value is our answer. And also when it finds the integer, it doesn't stop, it goes on to find the next greater value (or smaller) by traversing further down the tree. It's a tiny code :) TreeNode* getSuccessor(TreeNode* A, int B) { TreeNode *P=NULL; while(A!=NULL) { if(A->valright; } else if(A->val>B) { P=A; A=A->left; } } return P; TreeNode* getPredecessor(TreeNode* A, int B) { TreeNode *P=NULL; while(A!=NULL) { if(A->valright; } else if(A->val>=B) { A=A->left; } } return P;
I'm in tear watching your video sir, the way you spreading knowledge is on god tier, I coundn't been more satisfied with my life without learning from you.Much Love!
Yeah i stop C++ 25 years ago, and i busy with mathematic, until last year, and per chance i step on these videos on C++ and data structure, and he gave me another breath and i start learn what i lost before, very effective __my back ground mathematic help me__ and now i just i have 80% of C++, and data structure 60%, and this second year is planed to make all data structure __special a complex tree with modern C++__ from scratch and both .
You haven't handled the case when current node is leaf node. Yet, still it is an excellent tutorial for DS and I will recommend this to other. I have learnt a lot from you. Thank you so much..
In Getsuccessor function instead of: "if(current->data < ancestor->data)" we must use :if(current->data data)" To ensure the data less or equal will be found in left subtree. Thanks for sharing your knowledge.
If it is the max element in the BST, it should return null. The video doesn't take this corner case into consideration. Anyway, another really fantastic video. I learned a lot from the whole series. Thank you.
if the right subtree is present, the successor will be the node with the minimum value in right subtree else successor will be the node where we took the last left turn while searching for the current node.
can you make videos on red black trees, greedy algo, kruskal algo and other topics that are in cormen. i went through mit videos i must say you are better than those fancy professors
FOR PREDECESSOR : - CASE 1 : we will have to find max in left subtree of the given node CASE 2: and when left subtree is not available curr = node_given ; ancs = root ; pred = NULL while ( ancs != NULL ) { if( ancs->data < curr->data ) { pred = ans; ancs = ancs->right; } else ancs = ancs->left; } return ancs;
Thanks for the video series. They've been really helpful for me these days. Can you please do a series on Balanced Binary trees and Tries as well. Thanks in advance.
@mycodeschool, thanks for the video!, but I believe you should create the video for the predeccessor, in the end people use this videos to learn, but also as reference... dont treat us bad :(
Hey, great video thanks a lot. I was wondering a few things about the code you wrote: Is it better in C++ to use nullptr instead of the C macro NULL ? Is temp a good variable name? Coud we call the variable "successor" to make clear we're returning the successor? Is this: while(temp->left != NULL_ temp=temp->left; equivalent to: while (temp = temp->left) { ; //do nothing } Which one is a better c++ idiom?
i dont know if its good practice, but it a different faster implementation in trade off for higher memory requierements Node* successor(Node * root, int data, Node * ancestor=NULL){ //if found, return either right sub or ancestor if(root->data==data){ if(root->right!=NULL)return root->right; else return ancestor; } // search for Node, if call for left sub, give self as arg if (datadata)return successor(root->left, data, root); else return successor(root->right, data, ancestor); }
dude, a single optimization to propose, why not maintain the successor while you find the node? if right subtree doesnt exists,we simply return that value.. this way we sorta save the second traversal in else conditon. ideally it would be o(h) + o(h) but when we maintain it, it would turn out to be only o(h) single go. Find could be modified as :- > Node* Find(Node* root,Node* succ, int data){ Node* ancestor = root; while(ancestor->data != data){ if(data < ancestor->data){ succ = ancestor; ancestor = ancestor->left; } else{ ancestor=ancestor->right; } } return ancestor; } so , as soon as else is triggered, we directly return the succ node that we maitained during FInd().
I noticed it's been a while since you uploaded any data structure videos. Will there be more, or is this the end of the line? Also, if you do continue the series, it would be cool to see a hashmap/hashtable implementation.
***** No this is not an end. My co-founder who was an amazing friend passed away in an accident and I have not been able to focus much after that. Its been a hit. I am trying to reset things and keep this project going. Expect some videos in this data structures series in August. Video creation is slow and creative process. But 4-5 videos in a month is still something that I can do. -Animesh Nayan Co-founder, MyCodeSchool
mycodeschool Wow, sorry to hear that. Not much I can really say other than that I feel for you and hope you come out the other side alright. It really makes the lack of videos seem insignificant by comparison, but I'm glad to hear that you are going to continue with your channel - it's very informative and I imagine helpful to a lot of people. Good luck and again, I'm very sorry to hear about your friend.
Hi! Your code had an error when I compiled it. The error is in the last line return successor; and says that successor undeclared (first use in this function). I delcared struct node * successor = NULL; at the top but then it doesn't return anything cause its Value is NULL and the value never changes inside the else statement! How can I fix it?
sir , in this we don't have condition to check if the element is largest ,then there will be no successor.Can we use a find max function to check if it is the largest element ? will it affect the time complexity ??
while(ancestor != current) will not work to find inorder successor of a element in right subtree. So if we change it to while(ancestor != null) i think it will work.
This entire playlist is a treasure. Downloaded all the videos and created multiple copies in my PC, my external hard drive and google drive. Cannot risk it losing in case of apocalypse. And whoever you are, a big thank you. You are a GOAT.
No, he is not a GOAT, He is a human
@@robinsoni4778 He capitalized GOAT. It stand for Greatest Of All Time.
kuch zyada ho gya...............tareef karne ka tarika tera mujhe kuch khas acha nhi laga 😂
@@Slim7073 That is ambiguous abbreviation. There could be 100 things it stand for. And "goat" sounds like a bad word.
@@konstantinrebrov675 it's a word used in many places, for example messi is the football goat, jordan the basket goat etc...
It’s been 10 YEARS since this playlist and people are still watching it, I don’t usually comment but Really Thank you for this masterpiece
After 2 Years...THis videos Helped the same.....i am sure till many years this videos will keep helping Students
yes it's still rocking he left us a treasure
yes today's date is 30/05/2020
2021 and still the easiest and understandable explanation of ds on yt
I am here on 20 july 2021
😂 This aged very well
Hi Sir, I have followed all your BST tutorials. It was very great and clear explanation. Initially I was afraid of learning BST. Now I can say I have learned BST confidently from your explanation. Thank you very much your contribution to helping programmers.
finally i find someone who explain all things with details thank you so much
I'm watching this series after my engineering, these data structures make much more sense now thank you so much
mycodeschool Your tutorials are BRILLIANT! Please do continue the series as soon as possible. Would like to see more on Trees, Graphs, Maps, Hash-tables etc.
I'm gonna hit Like 👍🏻to every video of this channel coz It Deserves !!
I am a beginner in DS. These videos helped me a lot to understand quickly. Thanks a lot. Please don't stop uploading. Keep going.
He stopped lol
He is no more in this cruel world :(
@@monikajha3500 what do you mean by that? :|
@@monikajha3500 No, he is alive.
@@noobcoder5988 sorry but sadly he is dead search for it
Yooo, this whole concept of BST is freaking amazing, almost magical. Thanks a lot for sharing this mate!
this play list is absolute bonus for every programmer who wants to get good at data structure , Many thanks to CS DOJO for suggesting this !!!!!
Hi I'm Kapil,
These codes for successor and predecessor seem to work fine. They keep on storing the pointer to nodes whose value is greater than (or less than) the given integer in the path of search for the integer and the latest updated value is our answer.
And also when it finds the integer, it doesn't stop, it goes on to find the next greater value (or smaller) by traversing further down the tree. It's a tiny code :)
TreeNode* getSuccessor(TreeNode* A, int B) {
TreeNode *P=NULL;
while(A!=NULL)
{
if(A->valright;
}
else if(A->val>B)
{
P=A;
A=A->left;
}
}
return P;
TreeNode* getPredecessor(TreeNode* A, int B) {
TreeNode *P=NULL;
while(A!=NULL)
{
if(A->valright;
}
else if(A->val>=B)
{
A=A->left;
}
}
return P;
It actually works fine, the time complexity is also O(h). I wonder why he used such a complex algorithm.
I'm in tear watching your video sir, the way you spreading knowledge is on god tier, I coundn't been more satisfied with my life without learning from you.Much Love!
Yeah i stop C++ 25 years ago, and i busy with mathematic, until last year, and per chance i step on these videos on C++ and data structure, and he gave me another breath and i start learn what i lost before, very effective __my back ground mathematic help me__ and now i just i have 80% of C++, and data structure 60%, and this second year is planed to make all data structure __special a complex tree with modern C++__ from scratch and both .
All videos are great,most important thing is that they are all very interactive and you have worked very hard in making them and teaching us.
Thankyou
This is THE PERFECT explanation of this concept.
You haven't handled the case when current node is leaf node. Yet, still it is an excellent tutorial for DS and I will recommend this to other. I have learnt a lot from you. Thank you so much..
It will fall into the current -> right==null case
finally completed the whole DS series :)
And got placed at google
@@kausshin5404 lol
@@kausshin5404 wait, really??
Congratulations
In Getsuccessor function instead of:
"if(current->data < ancestor->data)" we must use :if(current->data data)"
To ensure the data less or equal will be found in left subtree.
Thanks for sharing your knowledge.
i think you won't have to check equal condition since in BST, duplicate is not allowed anyways.
Completed all the 13 Videos on BST
I feel like a BST Master and able to complete most Leetcode problems on BST:)
getSucessor in case II is really insightful and elegant. That sums up this video.
Man...U are an inspiration for me.. You are just great.. No words can express your work.. Thanx for helping
Really, great stuff man. You have helped a lot of people. You should be really proud of yourself.
If it is the max element in the BST, it should return null. The video doesn't take this corner case into consideration. Anyway, another really fantastic video. I learned a lot from the whole series. Thank you.
Most enjoyable experience i ever had of online learning, so much love and respect.
Your videos are "the" best
Any plan to cover self balancing trees like Red Black or AVL trees
if the right subtree is present, the successor will be the node with the minimum value in right subtree else successor will be the node where we took the last left turn while searching for the current node.
brother make an updated playlist of ds-algo with same explanation . i have not words to express who you are
Kudos for your efforts in making concepts seem this easy ! Love your channel. Really helpful !!
Bro u are the best . cleared all doubts
can you make videos on red black trees, greedy algo, kruskal algo and other topics that are in cormen. i went through mit videos i must say you are better than those fancy professors
theNewBoston of Indian software youtubers!
Impressive. Thanks a million times. You are simply the best.
FOR PREDECESSOR : -
CASE 1 :
we will have to find max in left subtree of the given node
CASE 2:
and when left subtree is not available
curr = node_given ;
ancs = root ;
pred = NULL
while ( ancs != NULL ) {
if( ancs->data < curr->data ) {
pred = ans;
ancs = ancs->right;
}
else ancs = ancs->left;
}
return ancs;
Thanks for the video series. They've been really helpful for me these days.
Can you please do a series on Balanced Binary trees and Tries as well.
Thanks in advance.
Keep it up dude! you deserves appericiation
Dude, you just I locked my brain on this. Thank you so much!
your videos are the best i can find. I love u
+yoshinosakura Noooo. I love them more. :p
love me too
Sir,I am a big fan of this channel.Please upload videos of some more topics of Data Structures.
Thank you very much...step by step I like that!! Bravoooo!!! wish you could make more videos on computer science
Woh, you did a problem on iterative inorder traversal without stack!
This isn't inorder traversal
@mycodeschool, thanks for the video!, but I believe you should create the video for the predeccessor, in the end people use this videos to learn, but also as reference... dont treat us bad :(
Java code for inorder predecessor->
public Node inOrderPredecessor(Node root,int key){
Node current=search(root,key);
if(current==null)return null;
if(current.left!=null){
return max(current.left);
}else{
Node ancestor=root;
Node predecessor=null;
while(ancestor!=current){
if(key>ancestor.data){
predecessor=ancestor;
ancestor=ancestor.right;
}else if(key
Needed this. Thanks :)
Hey, great video thanks a lot.
I was wondering a few things about the code you wrote:
Is it better in C++ to use nullptr instead of the C macro NULL ?
Is temp a good variable name? Coud we call the variable "successor" to make clear we're returning the successor?
Is this:
while(temp->left != NULL_ temp=temp->left;
equivalent to:
while (temp = temp->left) {
; //do nothing
}
Which one is a better c++ idiom?
bro, please come back!
i dont know if its good practice, but it a different faster implementation in trade off for higher memory requierements
Node* successor(Node * root, int data, Node * ancestor=NULL){
//if found, return either right sub or ancestor
if(root->data==data){
if(root->right!=NULL)return root->right;
else return ancestor;
}
// search for Node, if call for left sub, give self as arg
if (datadata)return successor(root->left, data, root);
else return successor(root->right, data, ancestor);
}
you have a very good English!
Inorder presecessor code in c : enjoy guys :)
struct node* Getpresecessor( struct Node* root , int data ) {
// Search the Node - O(h)
struct node* current = Find(root,data);
if(current == NULL)
return NULL;
if(current->left != NULL) { //Case 1: Node has right subtree
return maxValueNode(current->left); // O(h)
}
else { //Case 2: No right subtree - O(h)
struct node* presecessor = NULL;
struct node* ancestor = root;
while( ancestor != current ) {
if( current -> key > ancestor -> key ) {
presecessor = ancestor; // so far this is the deepest node for which current node is in left
ancestor = ancestor->right;
}
else
ancestor = ancestor->left;
}
return presecessor;
}
}
struct node * maxValueNode(struct node* node)
{
struct node* current = node;
/* loop down to find the leftmost leaf */
while (current->right != NULL)
current = current->right;
return current;
}
// so far this is the deepest node for which current node is in left.
correction: left should be right.
Good analysis!
this is really really helpful. THANK YOU
very good explanation
Plss make more videos on graphs
Hats off.Its a treasure
i really enjoyed while watching each and every videos.
can you add some videos of threaded binary tree if possible.............
in the else part inside while loop ,we need a "sucessor=ancestor" there too i think (right subtree part)
update : - i am wrong . the code is correct. explanation is at 16:55 . not all nodes will have a successor. there is no successor the right most node.
dude, a single optimization to propose, why not maintain the successor while you find the node? if right subtree doesnt exists,we simply return that value.. this way we sorta save the second traversal in else conditon. ideally it would be o(h) + o(h) but when we maintain it, it would turn out to be only o(h) single go.
Find could be modified as :- >
Node* Find(Node* root,Node* succ, int data){
Node* ancestor = root;
while(ancestor->data != data){
if(data < ancestor->data){
succ = ancestor;
ancestor = ancestor->left;
}
else{
ancestor=ancestor->right;
}
}
return ancestor;
}
so , as soon as else is triggered, we directly return the succ node that we maitained during FInd().
Very helpful!
Great video. But it would have been much clearer if in case2 code, ancestor was named as temp and successor was named as ancestor.
Thank You Sir
I noticed it's been a while since you uploaded any data structure videos. Will there be more, or is this the end of the line? Also, if you do continue the series, it would be cool to see a hashmap/hashtable implementation.
***** No this is not an end. My co-founder who was an amazing friend passed away in an accident and I have not been able to focus much after that. Its been a hit. I am trying to reset things and keep this project going. Expect some videos in this data structures series in August. Video creation is slow and creative process. But 4-5 videos in a month is still something that I can do.
-Animesh Nayan
Co-founder, MyCodeSchool
mycodeschool Wow, sorry to hear that. Not much I can really say other than that I feel for you and hope you come out the other side alright. It really makes the lack of videos seem insignificant by comparison, but I'm glad to hear that you are going to continue with your channel - it's very informative and I imagine helpful to a lot of people. Good luck and again, I'm very sorry to hear about your friend.
***** in addition, he was the No.1 coder of India!!
You've been very helpful Animesh for a lot of people out there.
sir,please made video on combinations of sum
Hi!
Your code had an error when I compiled it. The error is in the last line return successor; and says that successor undeclared (first use in this function).
I delcared struct node * successor = NULL; at the top but then it doesn't return anything cause its Value is NULL and the value never changes inside the else statement!
How can I fix it?
Thank u so much i finally understood this successor thing
This good initiative had a bad end.
Thank you is all I can say!
***** you said that you will be making more lessons on problems on Binary Trees and Binary trees in this video. Why did you stop ?
his best friend died in a car accident
sir , in this we don't have condition to check if the element is largest ,then there will be no successor.Can we use a find max function to check if it is the largest element ? will it affect the time complexity ??
Can you add one more lecture on avl tree before graph.. That is the thing which is missing in your lectures
while(ancestor != current) will not work to find inorder successor of a element in right subtree. So if we change it to while(ancestor != null) i think it will work.
Finally completed !!!
pls talk about n-ary tree
thank you sir it very much cleared way
great work
Thanks sir.....
did he cover AVL trees?
why there are ont avl tree?
what about 11, what case does it fall into
thank u bro
what is the successor of 27 or 25 in this case?
Excellent! Thank you.
Very Good!
I guess that successor=ancestor, you have to define outside the if block.
Am I correct please reply someone.
Plz tell me sir whats ur name??
Really amazing video
Thanks
Can't you traverse (right root and then left) and check if the next node you are going to traverse is the one you are looking the successor for?
Complexity would be O(n) for your approach.
AVL tree please
GOAT
how does it come back from 6 to 8?
what about AVL and B+ trees
How to find post order by given data in- order d b e a f c g and pre order a b d e c f g
simply first make the tree after that find post order as simple as that
Good tutorial, but in your else statement you missed succesor = ancestor;
nope bro, if we are going right, we dont have to move the succesor... see from 9:22 again... hope u'll get it
excellent
things r getting real tough...
share one tut on threaded binary tree if possible ;)
u are bossssssss
Sir is this only for time complexity ???
because you already posted tree traversal video.....
I like this.
11:072 Excuse me!!!😂😂
your all videos are awesome. why did you stop uploading videos bro ?
because one of the contributors humblefool unfortunately died.
Deserving ❤️❤️
great