Find Inorder Successor and Predecessor in a BST | Binary Search Tree | Babbar DSA Sheet | Amazon 🔥

Поделиться
HTML-код
  • Опубликовано: 17 сен 2024
  • #bst #binarysearchtree #competitiveprogramming #coding #dsa
    Hey, Guys in this video I have explained with code how we can solve the problem 'Find Inorder Successor and Predecessor in a BST'.
    Our Another Channel (Code up with Newton School) = / @codeupwithtwins6728
    Join our Telegram Channel for more Information
    🔰 Telegram Channel Link = t.me/CodeLibrary1
    🔰 Telegram Discussion Group Link = t.me/CodeLibra...
    🔰 Get 10% OFF on all GeeksforGeeks Courses
    Coupon Code = CODELIBRARY
    🔰 Array Playlist = • Love Babbar DSA 450 Qu...
    🔰 String Playlist = • Love Babbar DSA 450 Qu...
    🔰 Searching and Sorting Playlist = • Love Babbar DSA 450 Qu...
    🔰 Binary Tree Playlist = • Love Babbar DSA 450 Qu...
    🔰 Linked List Playlist = • Love Babbar DSA 450 Qu...
    🔰 Graph Playlist = • Love Babbar DSA 450 Qu...
    🔰 Dynamic Programming Playlist = • Love Babbar DSA 450 Qu...
    🔰 Informative Videos = • Informative Videos
    🔰 Love Babbar DSA Sheet: drive.google.c...
    Follow us on Instagram:
    🔰 Shailesh Yogendra : / shaileshyogendra
    🔰 Yogesh Yogendra : / i_am_yogesh_here
    Follow us on LinkedIn:
    🔰 Yogesh Yogendra : / yogesh-yogendra-26bbb518a
    🔰 Shailesh Yogendra : / shailesh-yogendra-8b13...
    Hope you like it. Comment if you have any doubt
    LIKE | SHARE | SUBSCRIBE

Комментарии • 49

  • @anshikgupta2993
    @anshikgupta2993 3 года назад +9

    Sir I was doing this with another array but this was the kind of explanation I was looking for. Thank you sir really helpful.

  • @adityashekhartiwary
    @adityashekhartiwary 3 года назад +3

    Have a look 5 lines in C++
    void findPreSuc(Node* root, Node*& pre, Node*& suc, int key)
    {
    if(!root) return ;
    findPreSuc(root->left,pre,suc,key);
    if(root->keykey>key && suc==0) suc=root;
    findPreSuc(root->right,pre,suc,key);
    }
    btw i really liked your approach specially that one right and extreme left part

    • @surajkumar-ci4qr
      @surajkumar-ci4qr 2 года назад

      Time complextiy is O(n).
      .
      Where, n is no of node and it will work on both the binary tree as well as binary search tree.
      Great job.

    • @yashvardhan6001
      @yashvardhan6001 2 года назад

      good code

  • @sanketkudapane9289
    @sanketkudapane9289 3 года назад +4

    Surely one of the best tutorials 👍 keep inspiring 💯

  • @vishalgarna12
    @vishalgarna12 7 месяцев назад +1

    Your explanation to good sir ji

  • @sujan_kumar_mitra
    @sujan_kumar_mitra 3 года назад +6

    Kudos to your consistency!

  • @raviashwin1157
    @raviashwin1157 3 года назад +4

    Bro Tere playlist abhi bahut popular hogi...best wishes❤️

  • @siddhantyadav4531
    @siddhantyadav4531 3 года назад

    Sir you are doing good work none of the you tuber is solving love babbar sir sheet

  • @shreyankshrestha9274
    @shreyankshrestha9274 3 года назад

    bhai tera code dekh kay he samj ata hai . keep it up bhai ;
    love from bihar :

  • @ashfaqhussain761
    @ashfaqhussain761 2 года назад

    excellent explanation bhaiya

  • @deshabhaktg6530
    @deshabhaktg6530 3 года назад

    Bhai you're my saviour❤❤❤

  • @user-og7my4so5d
    @user-og7my4so5d 3 месяца назад

    nice

  • @hiteshusingh8571
    @hiteshusingh8571 2 года назад

    Very nicely explained bhai.Keep it Up!

  • @arubansal3996
    @arubansal3996 2 года назад

    this video is awesome.

  • @softmedun6794
    @softmedun6794 3 месяца назад +1

    dimag ka dahi bana diya tune😅

  • @arjunagarwal2248
    @arjunagarwal2248 3 года назад

    simple explanation!!

  • @sincereeyes4991
    @sincereeyes4991 7 месяцев назад

  • @Saveindian
    @Saveindian 2 года назад

    Thanks

  • @rohandevaki4349
    @rohandevaki4349 2 года назад +1

    where are you handling the case for -1? at 15:05

  • @siddhantyadav4531
    @siddhantyadav4531 3 года назад

    Thanks 👍👍👍😊

  • @harshitavyas7497
    @harshitavyas7497 2 года назад

    too good!

  • @snehajain8104
    @snehajain8104 3 года назад

    Very nice videos ✨✨.... please make bst videos too🙈

  • @shivammaniharsahu1228
    @shivammaniharsahu1228 3 года назад

    really cool explanation keep going

  • @aadeshsharma0001
    @aadeshsharma0001 3 года назад

    bro tum shi smjhate ho

  • @leavesomethingforus3326
    @leavesomethingforus3326 2 года назад

    Nice bro ☺️

  • @CodeSolve-bySandeep
    @CodeSolve-bySandeep 2 года назад

    bhaiya aap kaun sa software use karte ho teaching ke liye? jispe likh kar samjha rhe ho?

  • @subhamengine1143
    @subhamengine1143 2 года назад

    op solution

  • @milton_tom
    @milton_tom Год назад

    can this be done with inorder traversal recursively?

  • @vmstudy9965
    @vmstudy9965 4 месяца назад

    Bhai aap one case bhul ni rhe ho...?

  • @VikashSingh-kg8xr
    @VikashSingh-kg8xr 3 года назад +1

    bhai aap kab se ye sheet solve kr rhe ho ki score 700+ ho gyi hai amezing please abhi aap kya kr rhe ho mujhe reply de do i mean job ya anything else . maine ye video apne college group me shere kr diya mera college nit calicut hai .

  • @sanyamdeepsingh7907
    @sanyamdeepsingh7907 3 года назад

    bhai agar jo key present nahi uske lie pre -1 aur suc -1 print karna ho to kaise kareng?

  • @himanshunagar1510
    @himanshunagar1510 3 года назад

    bhaiya same to same krne pr bhi run time error kyo aa rha hai ?

  • @krushnapatil9196
    @krushnapatil9196 3 года назад

    Successor and Inorder Successor dono alag alag hai kya?

    • @SatnamSingh-sk3hd
      @SatnamSingh-sk3hd 3 года назад

      wo btayenge kya nikalna h, mtlb inorder bola h to inorder me traverse krte time kya h pre and succ

  • @dharanyuvi6951
    @dharanyuvi6951 3 года назад

    Bro u r doing, such a great thing
    but it will be useful if u use more english words than hindi

  • @abhishekvardhan7472
    @abhishekvardhan7472 3 года назад

    can you put this code in github and post the link.

  • @willturner3440
    @willturner3440 3 года назад

    Bro in which company you are working?

  • @samiaimtiaz961
    @samiaimtiaz961 2 года назад

    Pdf bi upload ker dy

  • @tsk2038
    @tsk2038 3 года назад

    Is there code in java ?

    • @CodeLibrary
      @CodeLibrary  3 года назад

      no it is in c++

    • @jaydalsaniya6986
      @jaydalsaniya6986 2 года назад

      static Node inpre( Node node ){
      // We will come here only if the node's atleast one left exist
      // one left - extreme right
      node = node.left ;
      while( node.right != null )
      node = node.right ;
      return node ;
      }
      static Node insuc( Node node ){
      // We will come here only if node's atleast one right exist
      // one right - extreme left
      node = node.right ;
      while( node.left != null )
      node = node.left ;
      return node ;
      }
      public static void findPreSuc(Node root, Res p, Res s, int key)
      {
      if( root == null ) return ;
      if( root.data == key ){
      // see if the node has both left or right
      // then we need to update its pre or succ
      if( root.left != null )p.pre = inpre( root ) ;
      if( root.right != null )s.succ = insuc( root ) ;
      }
      else if( key < root.data ){
      // if you go to the left update successor
      // because it may happen that it won't have left node
      s.succ = root ;
      findPreSuc( root.left , p , s , key ) ;
      }
      else {
      // if you go to the right update predecessor
      // because it may happen that it won't have right node
      p.pre = root ;
      findPreSuc( root.right , p , s , key ) ;
      }
      }

  • @kumarivandana1554
    @kumarivandana1554 3 года назад

    How it's printing -1 if succ or pred does not exist ?

    • @meerakoul4167
      @meerakoul4167 2 года назад

      may be in starting we had intializing the value as -1 while first time calling presucc function