Inorder Successor in a binary search tree

Поділитися
Вставка
  • Опубліковано 1 гру 2024

КОМЕНТАРІ • 169

  • @DhirendraSingh03
    @DhirendraSingh03 5 років тому +275

    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 років тому +4

      No, he is not a GOAT, He is a human

    • @Slim7073
      @Slim7073 5 років тому +23

      @@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 роки тому +2

      @@Slim7073 That is ambiguous abbreviation. There could be 100 things it stand for. And "goat" sounds like a bad word.

    • @danilo2735
      @danilo2735 4 роки тому +9

      @@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 місяців тому +4

    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 років тому +46

    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 років тому +2

      yes it's still rocking he left us a treasure

    • @manishpandey3803
      @manishpandey3803 4 роки тому +2

      yes today's date is 30/05/2020

    • @sudhanshu9831
      @sudhanshu9831 3 роки тому +1

      2021 and still the easiest and understandable explanation of ds on yt

    • @AmanKUMAR-vq1ls
      @AmanKUMAR-vq1ls 3 роки тому +1

      I am here on 20 july 2021

    • @jatinvashisht4293
      @jatinvashisht4293 3 роки тому +1

      😂 This aged very well

  • @narayankaadda772
    @narayankaadda772 7 років тому +4

    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.

  • @AnonymousCoder7
    @AnonymousCoder7 Рік тому +1

    I'm gonna hit Like 👍🏻to every video of this channel coz It Deserves !!

  • @darshanbhat9457
    @darshanbhat9457 9 років тому +31

    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 років тому +8

      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

  • @RAFAHOUSSAM
    @RAFAHOUSSAM 7 місяців тому +1

    finally i find someone who explain all things with details thank you so much

  • @shelbygt5004
    @shelbygt5004 10 років тому +7

    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.

  • @Leon-hg1ph
    @Leon-hg1ph 4 роки тому +5

    Yooo, this whole concept of BST is freaking amazing, almost magical. Thanks a lot for sharing this mate!

  • @prudvi01
    @prudvi01 3 роки тому +1

    I'm watching this series after my engineering, these data structures make much more sense now thank you so much

  • @yuiooiuyyuiooiuyyuio
    @yuiooiuyyuiooiuyyuio 8 років тому +6

    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 роки тому +1

      It actually works fine, the time complexity is also O(h). I wonder why he used such a complex algorithm.

  • @Drogon-Gaming
    @Drogon-Gaming 4 роки тому +1

    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 роки тому +1

    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 років тому +1

    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

  • @sarveshp1727
    @sarveshp1727 2 роки тому

    This is THE PERFECT explanation of this concept.

  • @1gouravgg
    @1gouravgg 10 років тому +40

    finally completed the whole DS series :)

  • @sarveshsant1337
    @sarveshsant1337 7 років тому +2

    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.

  • @shubhammohapatra7766
    @shubhammohapatra7766 3 роки тому +1

    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..

  • @parthkhanna8542
    @parthkhanna8542 4 роки тому

    Man...U are an inspiration for me.. You are just great.. No words can express your work.. Thanx for helping

  • @iamparitosh
    @iamparitosh 3 роки тому +2

    Completed all the 13 Videos on BST
    I feel like a BST Master and able to complete most Leetcode problems on BST:)

  • @findoc9282
    @findoc9282 3 роки тому

    Most enjoyable experience i ever had of online learning, so much love and respect.

  • @harinijeyaraman8789
    @harinijeyaraman8789 4 роки тому +2

    Kudos for your efforts in making concepts seem this easy ! Love your channel. Really helpful !!

  • @shubhamgoyal3100
    @shubhamgoyal3100 6 років тому +1

    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.

  • @prashantbacchewar8194
    @prashantbacchewar8194 9 років тому +3

    Your videos are "the" best
    Any plan to cover self balancing trees like Red Black or AVL trees

  • @sumitsaini1601
    @sumitsaini1601 4 роки тому

    getSucessor in case II is really insightful and elegant. That sums up this video.

  • @codingandmathvideos
    @codingandmathvideos 10 років тому +4

    Impressive. Thanks a million times. You are simply the best.

  • @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.

  • @sajalagrawal1430
    @sajalagrawal1430 6 років тому +1

    Bro u are the best . cleared all doubts

  • @Roover_sa
    @Roover_sa 4 роки тому +1

    brother make an updated playlist of ds-algo with same explanation . i have not words to express who you are

  • @stage666
    @stage666 9 років тому +4

    your videos are the best i can find. I love u

    • @monicaslv323
      @monicaslv323 9 років тому +1

      +yoshinosakura Noooo. I love them more. :p

    • @prabaljainn
      @prabaljainn 3 роки тому

      love me too

  • @bharaniakella7734
    @bharaniakella7734 7 років тому +1

    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

  • @RahulSharma-hp6hv
    @RahulSharma-hp6hv 9 років тому +1

    Keep it up dude! you deserves appericiation

  • @nitinjaiman
    @nitinjaiman 10 років тому +16

    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

  • @AbhishekKumar-ff9vg
    @AbhishekKumar-ff9vg 4 роки тому

    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;

  • @saiudaybhaskarmudivarty7502
    @saiudaybhaskarmudivarty7502 7 років тому +1

    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.

  • @Marko-vb2mi
    @Marko-vb2mi 5 років тому +1

    Dude, you just I locked my brain on this. Thank you so much!

  • @ScrappyVids
    @ScrappyVids 7 років тому +3

    @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 :(

  • @rahil_rehan
    @rahil_rehan 3 роки тому

    theNewBoston of Indian software youtubers!

  • @amateurbeginner7538
    @amateurbeginner7538 7 років тому +3

    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.

  • @shradheytripathi7564
    @shradheytripathi7564 8 років тому

    Sir,I am a big fan of this channel.Please upload videos of some more topics of Data Structures.

  • @sumitsaini1601
    @sumitsaini1601 7 років тому +2

    Woh, you did a problem on iterative inorder traversal without stack!

    • @jonsnow9246
      @jonsnow9246 4 роки тому

      This isn't inorder traversal

  • @williamwambua7710
    @williamwambua7710 3 роки тому

    Thank you very much...step by step I like that!! Bravoooo!!! wish you could make more videos on computer science

  • @techswissknife2858
    @techswissknife2858 3 роки тому +1

    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?

  • @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().

  • @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?

  • @RaviRanjan_ssj4
    @RaviRanjan_ssj4 9 років тому +3

    ***** 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

  • @butlikereally
    @butlikereally 6 років тому +1

    this is really really helpful. THANK YOU

  • @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 роки тому +1

      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.

  • @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);
    }

  • @arunkumargupta1947
    @arunkumargupta1947 9 років тому

    i really enjoyed while watching each and every videos.
    can you add some videos of threaded binary tree if possible.............

  • @olly779
    @olly779 7 років тому

    you have a very good English!

  • @kritikasinghal8015
    @kritikasinghal8015 6 років тому +1

    sir,please made video on combinations of sum

  • @bpunsky
    @bpunsky 10 років тому +2

    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 років тому +59

      ***** 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 років тому +7

      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 років тому +4

      ***** in addition, he was the No.1 coder of India!!

    • @wingzero1912
      @wingzero1912 8 років тому +1

      You've been very helpful Animesh for a lot of people out there.

  • @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.

  • @wangchi562
    @wangchi562 Рік тому

    bro, please come back!

  • @namangupta2587
    @namangupta2587 5 років тому +1

    Plss make more videos on graphs

  • @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.

  • @shaiksoofi3741
    @shaiksoofi3741 4 роки тому

    Hats off.Its a treasure

  • @ankitsingh8087
    @ankitsingh8087 7 років тому

    Can you add one more lecture on avl tree before graph.. That is the thing which is missing in your lectures

  • @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 ??

  • @zaneran5933
    @zaneran5933 8 років тому +1

    Good analysis!

  • @VC-kj9yx
    @VC-kj9yx 5 років тому

    Thank u so much i finally understood this successor thing

  • @gobibs1
    @gobibs1 6 років тому +1

    pls talk about n-ary tree

  • @niyas09
    @niyas09 6 років тому

    very good explanation

  • @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.

  • @kautukraj
    @kautukraj 4 роки тому +1

    Very helpful!

  • @RP-th8in
    @RP-th8in 9 років тому +1

    what about 11, what case does it fall into

  • @---xk4iw
    @---xk4iw 9 років тому +1

    why there are ont avl tree?

  • @worldfromhome4033
    @worldfromhome4033 2 роки тому

    Thank you is all I can say!

  • @santwanadutta4488
    @santwanadutta4488 5 років тому

    I guess that successor=ancestor, you have to define outside the if block.
    Am I correct please reply someone.

  • @Blanke-i3h
    @Blanke-i3h 5 років тому

    what is the successor of 27 or 25 in this case?

  • @siddalingammakasbag5360
    @siddalingammakasbag5360 6 років тому

    thank you sir it very much cleared way

  • @rohankademani6406
    @rohankademani6406 3 роки тому

    Finally completed !!!

  • @rimpinag6346
    @rimpinag6346 4 роки тому

    Plz tell me sir whats ur name??
    Really amazing video

  • @SumitKumar-fn3gj
    @SumitKumar-fn3gj 5 років тому +1

    Thank You Sir

  • @DevGamerShripadAgashe
    @DevGamerShripadAgashe 6 років тому +2

    AVL tree please

  • @TonyDaExpert
    @TonyDaExpert 3 роки тому

    did he cover AVL trees?

  • @looploop6612
    @looploop6612 5 років тому

    how does it come back from 6 to 8?

  • @PROcrastiDRIVESVofficial
    @PROcrastiDRIVESVofficial 8 років тому

    Excellent! Thank you.

  • @roshantopno1253
    @roshantopno1253 7 років тому

    great work

  • @gauravchauhan873
    @gauravchauhan873 4 роки тому

    what about AVL and B+ trees

  • @scriptkiddie6151
    @scriptkiddie6151 3 роки тому

    This good initiative had a bad end.

  • @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

  • @usama57926
    @usama57926 6 років тому +3

    thank u bro

  • @heenagirdher6443
    @heenagirdher6443 6 років тому +1

    Thanks sir.....

  • @gabrielpereiramendes3463
    @gabrielpereiramendes3463 5 років тому

    Very Good!

  • @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

  • @ArjunSoota
    @ArjunSoota 5 років тому +1

    GOAT

  • @manojpatial2404
    @manojpatial2404 10 років тому

    share one tut on threaded binary tree if possible ;)

  • @sheardz6380
    @sheardz6380 9 років тому +1

    Thanks

  • @hafizulislamhimel7742
    @hafizulislamhimel7742 8 років тому

    Sir is this only for time complexity ???
    because you already posted tree traversal video.....

  • @amateurbeginner7538
    @amateurbeginner7538 7 років тому +4

    u are bossssssss

  • @meghasyam427
    @meghasyam427 6 років тому

    things r getting real tough...

  • @effy1219
    @effy1219 7 років тому

    excellent

  • @albertpatterson8164
    @albertpatterson8164 7 років тому

    I like this.

  • @saipratapdannana8048
    @saipratapdannana8048 6 років тому

    your all videos are awesome. why did you stop uploading videos bro ?

  • @sandeepkumawat4982
    @sandeepkumawat4982 4 роки тому +1

    11:072 Excuse me!!!😂😂

  • @kashishmiglani6576
    @kashishmiglani6576 8 років тому

    great

  • @ShivamKhantwal94
    @ShivamKhantwal94 3 роки тому

    Deserving ❤️❤️