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
Sir I was doing this with another array but this was the kind of explanation I was looking for. Thank you sir really helpful.
You are most welcome
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
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.
good code
Surely one of the best tutorials 👍 keep inspiring 💯
Your explanation to good sir ji
Kudos to your consistency!
Bro Tere playlist abhi bahut popular hogi...best wishes❤️
Sir you are doing good work none of the you tuber is solving love babbar sir sheet
bhai tera code dekh kay he samj ata hai . keep it up bhai ;
love from bihar :
excellent explanation bhaiya
Bhai you're my saviour❤❤❤
nice
Very nicely explained bhai.Keep it Up!
this video is awesome.
dimag ka dahi bana diya tune😅
simple explanation!!
❤
Thanks
where are you handling the case for -1? at 15:05
Thanks 👍👍👍😊
too good!
Very nice videos ✨✨.... please make bst videos too🙈
really cool explanation keep going
Thanks!
bro tum shi smjhate ho
Nice bro ☺️
bhaiya aap kaun sa software use karte ho teaching ke liye? jispe likh kar samjha rhe ho?
op solution
can this be done with inorder traversal recursively?
Bhai aap one case bhul ni rhe ho...?
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 .
mai abhi 3rd year me hu....
@@CodeLibrary which college?
bhai agar jo key present nahi uske lie pre -1 aur suc -1 print karna ho to kaise kareng?
bhaiya same to same krne pr bhi run time error kyo aa rha hai ?
Successor and Inorder Successor dono alag alag hai kya?
wo btayenge kya nikalna h, mtlb inorder bola h to inorder me traverse krte time kya h pre and succ
Bro u r doing, such a great thing
but it will be useful if u use more english words than hindi
can you put this code in github and post the link.
Bro in which company you are working?
Amazon
Pdf bi upload ker dy
Is there code in java ?
no it is in c++
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 ) ;
}
}
How it's printing -1 if succ or pred does not exist ?
may be in starting we had intializing the value as -1 while first time calling presucc function