L40. Search in a Binary Search Tree | BST | C++ | Java

  Рет қаралды 127,813

take U forward

take U forward

Күн бұрын

Пікірлер: 99
@takeUforward
@takeUforward 3 жыл бұрын
Please likeeee, shareeee and subscribeeeeeeee :) Also follow me at Insta: Striver_79
@pritishpattnaik4674
@pritishpattnaik4674 2 жыл бұрын
My approach : TreeNode* searchBST(TreeNode* root, int val) { if (root == NULL) return NULL; if (root->val == val) return root; if (val < root->val) return searchBST(root->left, val); else return searchBST(root->right, val); }
@rollercoaster9719
@rollercoaster9719 Жыл бұрын
Same
@abhaykumarsingh3884
@abhaykumarsingh3884 2 ай бұрын
Are auxialiary space use ho rhi isme
@CaseyXd-e3l
@CaseyXd-e3l 2 ай бұрын
It will be log2n -1 auxiliary space right ? Please clarify
@sarangkumarsingh7901
@sarangkumarsingh7901 3 ай бұрын
Awesome.........Trees mein pehli baar khud se kuch kiya.......
@aiartisry
@aiartisry 3 жыл бұрын
Almost about to finish free ka tree series... :) Thank you so much for such amazing content. Your hard work is appreciable. After watching a video I always try to explain in same way how you used to explain intuition and dry run each step. It helps me a lot and also increases my code quality by Looking at your code. 🙌
@satyapraneethkatta1652
@satyapraneethkatta1652 3 жыл бұрын
This is best series on Trees I have ever come across on youtube. Striver salute to your passion and commitment to teaching people
@Anand-zg6jv
@Anand-zg6jv 3 жыл бұрын
bhai 1 no.content hai aur samjhaya bhut acche se hai ....bss abhi paid mt krna😂😂😂😂 plzzzzz abhi tree aadha hi pda hai aur graph poora baaki hai
@abhishekkumar-fe8lw
@abhishekkumar-fe8lw 7 ай бұрын
bhai konsi company ho tum abhi?
@shivangisrivastava1158
@shivangisrivastava1158 2 жыл бұрын
Thank you so much for BST !! Improving with every video.
@MandeepKumar-ue3zy
@MandeepKumar-ue3zy 3 жыл бұрын
BST can also have depth N(if tree is skwed) it's no always Logn height.
@takeUforward
@takeUforward 3 жыл бұрын
Yes it can be, but generally in all test cases it will be log 2 n, i have repeatedly used almost in all cases.
@tusharnain6652
@tusharnain6652 2 жыл бұрын
That's where AVL trees come.
@niharika_042
@niharika_042 8 ай бұрын
thank you so much Vi 🙂I was almost to complete my tree series,the way of explanation i loved it a lot.
@iamnottech8918
@iamnottech8918 4 ай бұрын
yes recursive solution is also easy and possible in case u are thinking
@shaikfahim1232
@shaikfahim1232 2 жыл бұрын
class Solution { public: TreeNode* searchBST(TreeNode* root, int val) { if(!root) return NULL; if(root->val==val) return root; if(root->left && valval) return searchBST(root->left,val); if(root->right && val>root->val) return searchBST(root->right,val); return NULL; } };
@spandanrastogi7144
@spandanrastogi7144 Жыл бұрын
2 Line Java Recursive Solution Based on Same Approach : public TreeNode searchBST(TreeNode root, int val) { if(root == null || root.val == val) return root; return val < root.val ? searchBST(root.left , val) : searchBST(root.right, val); }
@Nikhil-Tomar
@Nikhil-Tomar 5 ай бұрын
I think one correction should be there. The traversal time will not be log(N) for almost all cases
@iamnottech8918
@iamnottech8918 4 ай бұрын
He mentioned that
@yusrax3
@yusrax3 3 ай бұрын
in that case we have Avl tree to handle such scenario
@ganeshjaggineni4097
@ganeshjaggineni4097 4 ай бұрын
NICE SUPER EXCELLENT MOTIVATED
@VivekSharma-eh2tv
@VivekSharma-eh2tv 5 ай бұрын
sir 10 can also lie on the lesser part -> the point is to make the right node greater than the root's value so we can make the right node of any node 10 , that is how the lesser part will have the greater node . Please somehow reply if i go somewhere wrong
@enigmanarratives1
@enigmanarratives1 2 жыл бұрын
what about if we are given a linked list wont it be O(N) time comp ? like flatten binary tree Q we had all roots in right
@sudiptamukherjee8216
@sudiptamukherjee8216 3 күн бұрын
WE CAN USE RECURSION ALOS.
@apmotivationakashparmar722
@apmotivationakashparmar722 Ай бұрын
Thank you So much !
@madetolaugh3476
@madetolaugh3476 2 жыл бұрын
Could someone please explain to me the difference between...... return searchBST(root.left,val); and searchBST(root.left,val) ? Thanks in advance
@tejas7379
@tejas7379 2 жыл бұрын
In first case "return searchBST()" you will be returning whatever value your recursive call returns. Lets say I store a returned value in a variable, "val = searchBST()", and then return the val like "return val", what you are doing is returning what you got from function call. That in short is "return searchBST()". (Try to construct recursive tree on paper) For first case: 1 return [ function(root->right) ] right) ]
@piyushacharya7696
@piyushacharya7696 2 жыл бұрын
in short if you have a return type except void then add return fxn() or else fxn()
@himanshidafouty347
@himanshidafouty347 4 ай бұрын
Understood
@paraskamboj1039
@paraskamboj1039 3 ай бұрын
thankyou sir ji
@shaiksoofi3741
@shaiksoofi3741 4 ай бұрын
understod
@vaibhavpoliwal2820
@vaibhavpoliwal2820 3 жыл бұрын
Bro you are doing superb work, very very thanks
@dingo_5998
@dingo_5998 2 жыл бұрын
Thank you bhaiya for this😊😊😊
@spartant_1212
@spartant_1212 4 ай бұрын
Please include leetcode problem number in the description.
@Shivi32590
@Shivi32590 4 ай бұрын
thank you
@khitijkarmakar
@khitijkarmakar Жыл бұрын
Need help , after doimg this playlist is there any other type of trees i should also learn? (AVL RED BLACK Etc)
@UECAshutoshKumar
@UECAshutoshKumar Жыл бұрын
Thank you sir
@DevanshuAugusty
@DevanshuAugusty Жыл бұрын
space complexity for this is O(1) ?
@herculean6748
@herculean6748 Жыл бұрын
Could anyone please tell me where the articles from the sheet are??
@chiragbansod8252
@chiragbansod8252 8 ай бұрын
understood
@harshitjaiswal9439
@harshitjaiswal9439 9 ай бұрын
understood.
@shouvikdatta6831
@shouvikdatta6831 2 жыл бұрын
Bro, is it preferred to use conditional operator in interviews instead of if else? Bcz the code looks complex using conditional operator.
@ganeshkamath89
@ganeshkamath89 2 жыл бұрын
Both are fine, as long as it is easy to read.
@ramavathnandhini2347
@ramavathnandhini2347 Жыл бұрын
thankyou striver ..🙌
@abhaythakur2597
@abhaythakur2597 Жыл бұрын
well explained
@Shivamkumar-xu6hu
@Shivamkumar-xu6hu 2 жыл бұрын
Good one
@nagavedareddy5891
@nagavedareddy5891 2 жыл бұрын
Huge respect ❤👏
@abhijitkrao283
@abhijitkrao283 Жыл бұрын
If bool is to be returned instead of pointer, how can that be done ?
@iamnottech8918
@iamnottech8918 4 ай бұрын
Recursion or in Iterative when null then false rest case true
@nileshsinha7869
@nileshsinha7869 3 жыл бұрын
Loving the series❤
@hitheshpk6030
@hitheshpk6030 2 жыл бұрын
UNDERSTOOD
@sujan_kumar_mitra
@sujan_kumar_mitra 3 жыл бұрын
Understood
@rishabhgupta9846
@rishabhgupta9846 Жыл бұрын
understood
@ajayypalsingh
@ajayypalsingh 2 жыл бұрын
💚
@sakshamsharma648
@sakshamsharma648 2 жыл бұрын
great
@SibiRanganathL
@SibiRanganathL 18 күн бұрын
Undetstood
@AmitKumar-je9qo
@AmitKumar-je9qo 3 жыл бұрын
Bhaiya....string ka lecture nhi bnega??
@t-anime517
@t-anime517 Жыл бұрын
Understood 😊
@dreamyme543
@dreamyme543 2 жыл бұрын
Understood:)
@piyushacharya7696
@piyushacharya7696 2 жыл бұрын
reach++
@momilijaz271
@momilijaz271 2 жыл бұрын
done
@p38_amankuldeep75
@p38_amankuldeep75 2 жыл бұрын
💝🧡💝
@Telugu_europe
@Telugu_europe 2 жыл бұрын
US
@mohdhammadsiddiqui7598
@mohdhammadsiddiqui7598 2 жыл бұрын
Can anyone tell me the problem in this short code on the commented line if i am writing if instead of else if run time error (member access within null pointer ) is coming @takeUforward class Solution { public: TreeNode* searchBST(TreeNode* node, int key) { if(node==NULL) return node; while(node!=NULL && node->val!=key) { if(key>(node->val)) node=node->right; else if(keyval)) node=node->left;//comment } return node; } };
@psychointruder5203
@psychointruder5203 2 жыл бұрын
because the value of node became null after the if statement in case if value was greater and not found ,and if you try to execute the next if there you dont have a check for the null node thus entering a null pointer, thats the reason i guess
@mohdhammadsiddiqui7598
@mohdhammadsiddiqui7598 2 жыл бұрын
@@psychointruder5203 got thanx , thanx for the comment
@theenglishclub9970
@theenglishclub9970 Жыл бұрын
what is the corrected code for your above code now? @@mohdhammadsiddiqui7598
@AbhishekSharma-ip4df
@AbhishekSharma-ip4df Жыл бұрын
HEY Striver bro 😓😓please give back the geeks for geeks link beside every question. We have made hundreds of questions on GFG we started coding on GFG because it was in your sheet now if u only remove this how will we revise the question??????????? Now we have to search each question on GFG first then we are doing it, that is taking lot of time. If u have to put coding ninja link put it but don't remove GFG links.🙏🙏🙏🙏🙏🙏🙏🙏 GFG GFG GFG GFG GFG GFG GFG GFG GFG GFG GFG GFG GFG GFG !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
@KaushikSharma-c3q
@KaushikSharma-c3q Жыл бұрын
.....................
@adityapandey23
@adityapandey23 2 ай бұрын
Understood
@rishabhkumar8115
@rishabhkumar8115 3 жыл бұрын
Bro you are doing superb work, very very thanks
@pratyush_779
@pratyush_779 2 ай бұрын
understood
@tanishkumar6682
@tanishkumar6682 Жыл бұрын
understood
@jaiminsolanki5478
@jaiminsolanki5478 2 жыл бұрын
Understood
@rishabhkumar8115
@rishabhkumar8115 3 жыл бұрын
Bro you are doing superb work, very very thanks
@NikhilGupta-zo5jh
@NikhilGupta-zo5jh 2 жыл бұрын
Understood
@rishabhkumar8115
@rishabhkumar8115 3 жыл бұрын
Bro you are doing superb work, very very thanks
@roopeshn3301
@roopeshn3301 2 жыл бұрын
Understood
@rishabhkumar8115
@rishabhkumar8115 3 жыл бұрын
Bro you are doing superb work, very very thanks
@rishabhkumar8115
@rishabhkumar8115 3 жыл бұрын
Bro you are doing superb work, very very thanks
@rishabhkumar8115
@rishabhkumar8115 3 жыл бұрын
Bro you are doing superb work, very very thanks
@rishabhkumar8115
@rishabhkumar8115 3 жыл бұрын
Bro you are doing superb work, very very thanks
@rishabhkumar8115
@rishabhkumar8115 3 жыл бұрын
Bro you are doing superb work, very very thanks
@rishabhkumar8115
@rishabhkumar8115 3 жыл бұрын
Bro you are doing superb work, very very thanks
@rishabhkumar8115
@rishabhkumar8115 3 жыл бұрын
Bro you are doing superb work, very very thanks
@ritikgupta9238
@ritikgupta9238 3 жыл бұрын
bro are you getting paid for writing spammy comments?
@rishabhkumar8115
@rishabhkumar8115 3 жыл бұрын
Bro you are doing superb work, very very thanks
@madetolaugh3476
@madetolaugh3476 2 жыл бұрын
Thanks bro
@rishabhkumar8115
@rishabhkumar8115 3 жыл бұрын
Bro you are doing superb work, very very thanks
@rishabhkumar8115
@rishabhkumar8115 3 жыл бұрын
Bro you are doing superb work, very very thanks
@rishabhkumar8115
@rishabhkumar8115 3 жыл бұрын
Bro you are doing superb work, very very thanks
@rishabhkumar8115
@rishabhkumar8115 3 жыл бұрын
Bro you are doing superb work, very very thanks
@rishabhkumar8115
@rishabhkumar8115 3 жыл бұрын
Bro you are doing superb work, very very thanks
@rishabhkumar8115
@rishabhkumar8115 3 жыл бұрын
Bro you are doing superb work, very very thanks
@parthsalat
@parthsalat 2 жыл бұрын
Are u using some sort of bot to do this? Pls tell...
@rishabhkumar8115
@rishabhkumar8115 3 жыл бұрын
Bro you are doing superb work, very very thanks
@rishabhkumar8115
@rishabhkumar8115 3 жыл бұрын
Bro you are doing superb work, very very thanks
@rishabhkumar8115
@rishabhkumar8115 3 жыл бұрын
Bro you are doing superb work, very very thanks
L41. Ceil in a Binary Search Tree | BST | C++ | Java
5:36
take U forward
Рет қаралды 119 М.
LeetCode was HARD until I Learned these 15 Patterns
13:00
Ashish Pratap Singh
Рет қаралды 577 М.
The Singing Challenge #joker #Harriet Quinn
00:35
佐助与鸣人
Рет қаралды 44 МЛН
They Chose Kindness Over Abuse in Their Team #shorts
00:20
I migliori trucchetti di Fabiosa
Рет қаралды 12 МЛН
10.1 AVL Tree - Insertion and Rotations
43:08
Abdul Bari
Рет қаралды 1,2 МЛН
L39. Introduction to Binary Search Tree | BST
8:54
take U forward
Рет қаралды 134 М.
New divisibility rule! (30,000 of them)
26:51
Stand-up Maths
Рет қаралды 276 М.
I gave 127 interviews. Top 5 Algorithms they asked me.
8:36
Sahil & Sarra
Рет қаралды 673 М.
L15. Check for Balanced Binary Tree | C++ | Java
12:30
take U forward
Рет қаралды 357 М.
Inorder Successor in a binary search tree
17:58
mycodeschool
Рет қаралды 362 М.
L53. Largest BST in Binary Tree
17:27
take U forward
Рет қаралды 166 М.
Racing Speedrunning Legend: Couriway
20:21
rekrap1
Рет қаралды 99 М.