Inorder Successor in a binary search tree

  Рет қаралды 362,579

mycodeschool

mycodeschool

Күн бұрын

Пікірлер: 169
@DhirendraSingh03
@DhirendraSingh03 5 жыл бұрын
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.
@robinsoni4778
@robinsoni4778 5 жыл бұрын
No, he is not a GOAT, He is a human
@Slim7073
@Slim7073 5 жыл бұрын
@@robinsoni4778 He capitalized GOAT. It stand for Greatest Of All Time.
@ApoorvaRajBhadani
@ApoorvaRajBhadani 5 жыл бұрын
kuch zyada ho gya...............tareef karne ka tarika tera mujhe kuch khas acha nhi laga 😂
@konstantinrebrov675
@konstantinrebrov675 4 жыл бұрын
@@Slim7073 That is ambiguous abbreviation. There could be 100 things it stand for. And "goat" sounds like a bad word.
@danilo2735
@danilo2735 4 жыл бұрын
@@konstantinrebrov675 it's a word used in many places, for example messi is the football goat, jordan the basket goat etc...
@llarn.i5103
@llarn.i5103 6 ай бұрын
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
@deeepbagadiya
@deeepbagadiya 8 жыл бұрын
After 2 Years...THis videos Helped the same.....i am sure till many years this videos will keep helping Students
@random-0
@random-0 5 жыл бұрын
yes it's still rocking he left us a treasure
@manishpandey3803
@manishpandey3803 4 жыл бұрын
yes today's date is 30/05/2020
@sudhanshu9831
@sudhanshu9831 3 жыл бұрын
2021 and still the easiest and understandable explanation of ds on yt
@AmanKUMAR-vq1ls
@AmanKUMAR-vq1ls 3 жыл бұрын
I am here on 20 july 2021
@jatinvashisht4293
@jatinvashisht4293 3 жыл бұрын
😂 This aged very well
@narayankaadda772
@narayankaadda772 7 жыл бұрын
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.
@RAFAHOUSSAM
@RAFAHOUSSAM 7 ай бұрын
finally i find someone who explain all things with details thank you so much
@Leon-hg1ph
@Leon-hg1ph 4 жыл бұрын
Yooo, this whole concept of BST is freaking amazing, almost magical. Thanks a lot for sharing this mate!
@darshanbhat9457
@darshanbhat9457 9 жыл бұрын
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.
@abhilashnair6660
@abhilashnair6660 6 жыл бұрын
He stopped lol
@monikajha3500
@monikajha3500 6 жыл бұрын
He is no more in this cruel world :(
@saeem01670
@saeem01670 6 жыл бұрын
@@monikajha3500 what do you mean by that? :|
@noobcoder5988
@noobcoder5988 5 жыл бұрын
@@monikajha3500 No, he is alive.
@random-0
@random-0 5 жыл бұрын
@@noobcoder5988 sorry but sadly he is dead search for it
@prudvi01
@prudvi01 3 жыл бұрын
I'm watching this series after my engineering, these data structures make much more sense now thank you so much
@shelbygt5004
@shelbygt5004 10 жыл бұрын
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.
@Drogon-Gaming
@Drogon-Gaming 4 жыл бұрын
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 !!!!!
@scotfsh5014
@scotfsh5014 2 жыл бұрын
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!
@__hannibaal__
@__hannibaal__ Жыл бұрын
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 .
@darshpreetsingh2010
@darshpreetsingh2010 5 жыл бұрын
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
@AnonymousCoder7
@AnonymousCoder7 Жыл бұрын
I'm gonna hit Like 👍🏻to every video of this channel coz It Deserves !!
@sarveshp1727
@sarveshp1727 2 жыл бұрын
This is THE PERFECT explanation of this concept.
@1gouravgg
@1gouravgg 10 жыл бұрын
finally completed the whole DS series :)
@kausshin5404
@kausshin5404 4 жыл бұрын
And got placed at google
@prajwalchoudhary4824
@prajwalchoudhary4824 4 жыл бұрын
@@kausshin5404 lol
@HARIHaran-ks7wp
@HARIHaran-ks7wp 3 жыл бұрын
@@kausshin5404 wait, really??
@manishkumargupta8677
@manishkumargupta8677 2 жыл бұрын
Congratulations
@shubhammohapatra7766
@shubhammohapatra7766 3 жыл бұрын
Really, great stuff man. You have helped a lot of people. You should be really proud of yourself.
@chayakumarsedutainment4799
@chayakumarsedutainment4799 4 жыл бұрын
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..
@ganapatibiswas5858
@ganapatibiswas5858 4 жыл бұрын
It will fall into the current -> right==null case
@sarveshsant1337
@sarveshsant1337 7 жыл бұрын
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.
@hughlee5648
@hughlee5648 2 жыл бұрын
i think you won't have to check equal condition since in BST, duplicate is not allowed anyways.
@parthkhanna8542
@parthkhanna8542 4 жыл бұрын
Man...U are an inspiration for me.. You are just great.. No words can express your work.. Thanx for helping
@findoc9282
@findoc9282 3 жыл бұрын
Most enjoyable experience i ever had of online learning, so much love and respect.
@iamparitosh
@iamparitosh 3 жыл бұрын
Completed all the 13 Videos on BST I feel like a BST Master and able to complete most Leetcode problems on BST:)
@yuiooiuyyuiooiuyyuio
@yuiooiuyyuiooiuyyuio 8 жыл бұрын
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;
@panavsethi3014
@panavsethi3014 4 жыл бұрын
It actually works fine, the time complexity is also O(h). I wonder why he used such a complex algorithm.
@harinijeyaraman8789
@harinijeyaraman8789 4 жыл бұрын
Kudos for your efforts in making concepts seem this easy ! Love your channel. Really helpful !!
@sumitsaini1601
@sumitsaini1601 4 жыл бұрын
getSucessor in case II is really insightful and elegant. That sums up this video.
@prashantbacchewar8194
@prashantbacchewar8194 9 жыл бұрын
Your videos are "the" best Any plan to cover self balancing trees like Red Black or AVL trees
@dr_920
@dr_920 4 жыл бұрын
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.
@codingandmathvideos
@codingandmathvideos 10 жыл бұрын
Impressive. Thanks a million times. You are simply the best.
@sajalagrawal1430
@sajalagrawal1430 6 жыл бұрын
Bro u are the best . cleared all doubts
@RahulSharma-hp6hv
@RahulSharma-hp6hv 9 жыл бұрын
Keep it up dude! you deserves appericiation
@rahil_rehan
@rahil_rehan 3 жыл бұрын
theNewBoston of Indian software youtubers!
@shubhamgoyal3100
@shubhamgoyal3100 6 жыл бұрын
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.
@Marko-vb2mi
@Marko-vb2mi 5 жыл бұрын
Dude, you just I locked my brain on this. Thank you so much!
@Roover_sa
@Roover_sa 4 жыл бұрын
brother make an updated playlist of ds-algo with same explanation . i have not words to express who you are
@nitinjaiman
@nitinjaiman 10 жыл бұрын
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
@saiudaybhaskarmudivarty7502
@saiudaybhaskarmudivarty7502 7 жыл бұрын
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.
@stage666
@stage666 9 жыл бұрын
your videos are the best i can find. I love u
@monicaslv323
@monicaslv323 9 жыл бұрын
+yoshinosakura Noooo. I love them more. :p
@prabaljainn
@prabaljainn 3 жыл бұрын
love me too
@shradheytripathi7564
@shradheytripathi7564 8 жыл бұрын
Sir,I am a big fan of this channel.Please upload videos of some more topics of Data Structures.
@bharaniakella7734
@bharaniakella7734 7 жыл бұрын
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
@rhythmpatel5665
@rhythmpatel5665 6 жыл бұрын
Needed this. Thanks :)
@williamwambua7710
@williamwambua7710 3 жыл бұрын
Thank you very much...step by step I like that!! Bravoooo!!! wish you could make more videos on computer science
@AbhishekKumar-ff9vg
@AbhishekKumar-ff9vg 3 жыл бұрын
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;
@sumitsaini1601
@sumitsaini1601 7 жыл бұрын
Woh, you did a problem on iterative inorder traversal without stack!
@jonsnow9246
@jonsnow9246 4 жыл бұрын
This isn't inorder traversal
@ScrappyVids
@ScrappyVids 7 жыл бұрын
@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 :(
@olly779
@olly779 7 жыл бұрын
you have a very good English!
@butlikereally
@butlikereally 6 жыл бұрын
this is really really helpful. THANK YOU
@shaiksoofi3741
@shaiksoofi3741 4 жыл бұрын
Hats off.Its a treasure
@amateurbeginner7538
@amateurbeginner7538 7 жыл бұрын
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; }
@AbhishekKumar-yv6ih
@AbhishekKumar-yv6ih 7 жыл бұрын
// so far this is the deepest node for which current node is in left. correction: left should be right.
@RaviRanjan_ssj4
@RaviRanjan_ssj4 9 жыл бұрын
***** you said that you will be making more lessons on problems on Binary Trees and Binary trees in this video. Why did you stop ?
@desihaxor5690
@desihaxor5690 5 жыл бұрын
his best friend died in a car accident
@wangchi562
@wangchi562 Жыл бұрын
bro, please come back!
@niyas09
@niyas09 6 жыл бұрын
very good explanation
@kautukraj
@kautukraj 4 жыл бұрын
Very helpful!
@VC-kj9yx
@VC-kj9yx 5 жыл бұрын
Thank u so much i finally understood this successor thing
@zaneran5933
@zaneran5933 8 жыл бұрын
Good analysis!
@HeWhoShalNotBeNamed_
@HeWhoShalNotBeNamed_ 4 жыл бұрын
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().
@arunkumargupta1947
@arunkumargupta1947 9 жыл бұрын
i really enjoyed while watching each and every videos. can you add some videos of threaded binary tree if possible.............
@kritikasinghal8015
@kritikasinghal8015 6 жыл бұрын
sir,please made video on combinations of sum
@manfredoweber3562
@manfredoweber3562 3 жыл бұрын
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); }
@worldfromhome4033
@worldfromhome4033 2 жыл бұрын
Thank you is all I can say!
@namangupta2587
@namangupta2587 5 жыл бұрын
Plss make more videos on graphs
@SumitKumar-fn3gj
@SumitKumar-fn3gj 5 жыл бұрын
Thank You Sir
@techswissknife2858
@techswissknife2858 3 жыл бұрын
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?
@vasantprabhu
@vasantprabhu 3 жыл бұрын
in the else part inside while loop ,we need a "sucessor=ancestor" there too i think (right subtree part)
@vasantprabhu
@vasantprabhu 3 жыл бұрын
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.
@rohankademani6406
@rohankademani6406 3 жыл бұрын
Finally completed !!!
@siddalingammakasbag5360
@siddalingammakasbag5360 6 жыл бұрын
thank you sir it very much cleared way
@scriptkiddie6151
@scriptkiddie6151 3 жыл бұрын
This good initiative had a bad end.
@gobibs1
@gobibs1 6 жыл бұрын
pls talk about n-ary tree
@bpunsky
@bpunsky 10 жыл бұрын
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.
@mycodeschool
@mycodeschool 10 жыл бұрын
***** 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
@bpunsky
@bpunsky 10 жыл бұрын
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.
@1gouravgg
@1gouravgg 10 жыл бұрын
***** in addition, he was the No.1 coder of India!!
@wingzero1912
@wingzero1912 8 жыл бұрын
You've been very helpful Animesh for a lot of people out there.
@heenagirdher6443
@heenagirdher6443 6 жыл бұрын
Thanks sir.....
@roshantopno1253
@roshantopno1253 7 жыл бұрын
great work
@frozentaco143
@frozentaco143 6 жыл бұрын
Great video. But it would have been much clearer if in case2 code, ancestor was named as temp and successor was named as ancestor.
@sheardz6380
@sheardz6380 9 жыл бұрын
Thanks
@usama57926
@usama57926 6 жыл бұрын
thank u bro
@ankitsingh8087
@ankitsingh8087 7 жыл бұрын
Can you add one more lecture on avl tree before graph.. That is the thing which is missing in your lectures
@listlist8982
@listlist8982 3 жыл бұрын
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?
@PROcrastiDRIVESVofficial
@PROcrastiDRIVESVofficial 8 жыл бұрын
Excellent! Thank you.
@gabrielpereiramendes3463
@gabrielpereiramendes3463 5 жыл бұрын
Very Good!
@cherrynaresh3111
@cherrynaresh3111 7 жыл бұрын
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.
@rimpinag6346
@rimpinag6346 4 жыл бұрын
Plz tell me sir whats ur name?? Really amazing video
@effy1219
@effy1219 7 жыл бұрын
excellent
@ArjunSoota
@ArjunSoota 5 жыл бұрын
GOAT
@---xk4iw
@---xk4iw 9 жыл бұрын
why there are ont avl tree?
@albertpatterson8164
@albertpatterson8164 7 жыл бұрын
I like this.
@namans9803
@namans9803 7 жыл бұрын
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 ??
@DevGamerShripadAgashe
@DevGamerShripadAgashe 6 жыл бұрын
AVL tree please
@RP-th8in
@RP-th8in 9 жыл бұрын
what about 11, what case does it fall into
@santwanadutta4488
@santwanadutta4488 5 жыл бұрын
I guess that successor=ancestor, you have to define outside the if block. Am I correct please reply someone.
@meghasyam427
@meghasyam427 6 жыл бұрын
things r getting real tough...
@TonyDaExpert
@TonyDaExpert 3 жыл бұрын
did he cover AVL trees?
@Blanke-i3h
@Blanke-i3h 5 жыл бұрын
what is the successor of 27 or 25 in this case?
@amateurbeginner7538
@amateurbeginner7538 7 жыл бұрын
u are bossssssss
@arjunpassi9945
@arjunpassi9945 9 жыл бұрын
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?
@rishigoley3521
@rishigoley3521 7 жыл бұрын
Complexity would be O(n) for your approach.
@gauravchauhan873
@gauravchauhan873 4 жыл бұрын
what about AVL and B+ trees
@looploop6612
@looploop6612 5 жыл бұрын
how does it come back from 6 to 8?
@ShivamKhantwal94
@ShivamKhantwal94 3 жыл бұрын
Deserving ❤️❤️
@musicalive1782
@musicalive1782 6 жыл бұрын
Good tutorial, but in your else statement you missed succesor = ancestor;
@harshitadevichopra8097
@harshitadevichopra8097 6 жыл бұрын
nope bro, if we are going right, we dont have to move the succesor... see from 9:22 again... hope u'll get it
@kashishmiglani6576
@kashishmiglani6576 8 жыл бұрын
great
@manojpatial2404
@manojpatial2404 10 жыл бұрын
share one tut on threaded binary tree if possible ;)
@rudavathvinod5916
@rudavathvinod5916 2 жыл бұрын
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
@alexrcrew1975
@alexrcrew1975 2 жыл бұрын
simply first make the tree after that find post order as simple as that
@sanketpawar3429
@sanketpawar3429 3 жыл бұрын
Lord Harsha😢
@antoniogargiulo9491
@antoniogargiulo9491 2 жыл бұрын
love u
@sandeepkumawat4982
@sandeepkumawat4982 4 жыл бұрын
11:072 Excuse me!!!😂😂
Binary tree traversal: Preorder, Inorder, Postorder
14:29
mycodeschool
Рет қаралды 964 М.
Binary search tree - Implementation in C/C++
18:36
mycodeschool
Рет қаралды 1,3 МЛН
Players push long pins through a cardboard box attempting to pop the balloon!
00:31
SIZE DOESN’T MATTER @benjaminjiujitsu
00:46
Natan por Aí
Рет қаралды 3,1 МЛН
Do you love Blackpink?🖤🩷
00:23
Karina
Рет қаралды 21 МЛН
L49. Inorder Successor/Predecessor in BST | 3 Methods
10:47
take U forward
Рет қаралды 151 М.
Coding Interview | Software Engineer @ Bloomberg (Part 1)
30:05
Keep On Coding
Рет қаралды 4,7 МЛН
Binary tree: Level Order Traversal
11:23
mycodeschool
Рет қаралды 612 М.
AVL Tree Explained - Algorithms & Data Structures #22
14:58
NeuralNine
Рет қаралды 3,5 М.
INORDER SUCCESSOR IN BST | PYTHON | LEETCODE 285
12:09
Cracking FAANG
Рет қаралды 6 М.
Data structures: Binary Search Tree
19:28
mycodeschool
Рет қаралды 1,3 МЛН
Delete a node from Binary Search Tree
18:27
mycodeschool
Рет қаралды 1,1 МЛН
Check if a binary tree is binary search tree or not
16:30
mycodeschool
Рет қаралды 380 М.
Reverse a string or linked list using stack.
16:25
mycodeschool
Рет қаралды 386 М.
Players push long pins through a cardboard box attempting to pop the balloon!
00:31