Lecture 66: Construct a Binary Tree from InOrder/PreOrder/PostOrder Traversal

  Рет қаралды 195,950

CodeHelp - by Babbar

CodeHelp - by Babbar

Күн бұрын

Пікірлер: 419
@srmtube2556
@srmtube2556 2 жыл бұрын
3 things I learn when I see this videos one is dsa concepts and other is consistency and commitment.
@inspiringzone12
@inspiringzone12 2 жыл бұрын
Absolutely right
@khushisrivastava357
@khushisrivastava357 Жыл бұрын
Hey are u there? actually i am not able to find the codes on the github link after lec 65..i think they are missing
@RohitSharma-vq7ro
@RohitSharma-vq7ro Жыл бұрын
​@@khushisrivastava357bro itna to khud try kar
@MSDHONI___
@MSDHONI___ Жыл бұрын
consistency is important bro
@anuragpandey8165
@anuragpandey8165 2 жыл бұрын
30:15 You clearly have a strong understanding about where the students could get stuck. Much love
@govindsuryavanshi6653
@govindsuryavanshi6653 Жыл бұрын
First I have completed all DSA series and now conclude this is Greatest ever DSA series to exist on youtube or paid courses. Your contribution will be remembered. You're God of DSA for us🙇‍♂ Thanks you.
@rishiagarwal813
@rishiagarwal813 11 ай бұрын
bro 65th lecture ke bad GitHub par code links nhi hai ky ??
@aayushiagarwal8797
@aayushiagarwal8797 Жыл бұрын
Thank you sir :), for making tree simple and understandable . I would like to highlight one point : Mapping solution will give wrong answer in case of duplicated nodes..... in such case , we can optimize findpos() function by checking from inStart to inEND .. int findpos(int in[],int x,int n,int s,int e) { for(int i=s;i
@ritikrastogi6438
@ritikrastogi6438 Жыл бұрын
Yes you're right
@simplesolutions2621
@simplesolutions2621 2 жыл бұрын
Best course! Best teacher! *Best time to learn!* 🔥
@sudhanshukumar3976
@sudhanshukumar3976 Жыл бұрын
mid course me kon coad dana band kar data hai ghanta best teacher
@yadvibhalla5392
@yadvibhalla5392 2 жыл бұрын
Best course ever🔥 consistency++;
@haiderali0801
@haiderali0801 2 жыл бұрын
The best DSA course ✨❤️
@anmol3
@anmol3 Жыл бұрын
Question 1 Test case 54 fails after addition of new test case Solution: Can't use maps. Use findPosition function and pass inorderStart and inorderEnd as arguments and not n(size). This happens because elements might be repeated.
@yashbanka8877
@yashbanka8877 Жыл бұрын
There is something wrong with this concept let me just clear it up . When you check for the location of the element in the inorder array you need not check it's location by traversing in the whole array instead , you need to check for the element in the required portion . In this case check for the element from in[inOrderStartIndex] to in[inOrderEndIndex] and you will just be fine
@shwetpatel2712
@shwetpatel2712 Жыл бұрын
Thanks Bro it works.
@PriyanshuSrivastava11fig
@PriyanshuSrivastava11fig Жыл бұрын
@@shwetpatel2712 please share the updated code. I'm not able to figure it out how to pass 54th test case using map
@shwetpatel2712
@shwetpatel2712 Жыл бұрын
@@PriyanshuSrivastava11fig sure here it is. class Solution{ public: int findposition(int element , int in[] , int start , int end) { for(int i = start ; i = n || inorder_start > inorder_end) { return NULL; } int element = pre[preorderindex]; Node* root = new Node(element); int position = findposition(element,in ,inorder_start , inorder_end); preorderindex++; root->left = solve(in,pre,n,preorderindex, inorder_start , position - 1); root-> right = solve(in , pre , n , preorderindex, position + 1 , inorder_end); return root; } Node* buildTree(int in[],int pre[], int n) { int preorderindex = 0; Node* temp = solve(in,pre,n, preorderindex, 0 , n-1); return temp; } };
@praveshishere
@praveshishere 6 ай бұрын
bro what would happend if elements are repeated in between inroderStart and inorderEnd
@top10shorts21
@top10shorts21 Жыл бұрын
The code mentioned in the video doesn't passes updated testcases --> So here is the updated code --> class Solution{ private: int Findposition(int in[] ,int inorderStart , int inorderEnd , int element ,int n){ for(int i = inorderStart ; i=n || inorderStart>inorderEnd){ return NULL ; } int element = pre[index++] ; // At every interation index is increasing Node* root = new Node(element); int position = Findposition(in , inorderStart , inorderEnd ,element, n); root->left = solve(in , pre , index , inorderStart , position-1 ,n); root->right = solve(in , pre , index , position+1 , inorderEnd ,n); return root ; } public: Node* buildTree(int in[],int pre[], int n) { // Code here int preorderindex = 0 ; //Pre order is NLR so First element is root . Node* ans = solve(in , pre , preorderindex , 0 , n-1 , n ); return ans ; }
@sourabhvishnoi9884
@sourabhvishnoi9884 Жыл бұрын
Really helpful, thanks
@anmol3
@anmol3 Жыл бұрын
Thanks
@vimalrai2092
@vimalrai2092 Жыл бұрын
it really helps, i was soo confused. thanks...
@AmitSharma-nv2oj
@AmitSharma-nv2oj Жыл бұрын
@@vimalrai2092 for which question
@khushdesai7600
@khushdesai7600 Жыл бұрын
can u tell us what you have change in this code?? because i have see this couple of time but , i could not catch it??
@rampratapmishra5962
@rampratapmishra5962 2 жыл бұрын
Wahh... Bhaiya mann gya aapko.. Kya consistency ha aapkee.. Ham ek video dekh nhi paarahe.. Aur aapke... New video... Aa rahe.. Ha bhaut saahi bhaiya.. Bass.. Aise hee consistentsy ham bhi continue kar paaye... Great bhaiya really great fan of you!!!!!! 🤗🤗
@vinayakgarg4628
@vinayakgarg4628 2 жыл бұрын
Here we can also use unordered map (T.C - O(1)) as we don't need data to be sorted, so the overall t.c will be O(n)
@deepakpal2168
@deepakpal2168 Жыл бұрын
Bro it will not work if we have dublicate values in array like (1 2 3 4 3)
@uditpanjiyar3203
@uditpanjiyar3203 Жыл бұрын
first question is explained very deeply but one more condition is also added on gfg that the values of root can be repeated thanks for the quality content
@ritesh_tiwari447
@ritesh_tiwari447 Жыл бұрын
for repeated nodes Just use map mpp and find element index by using {mpp[element].front()} then pop the queue
@prerakagarwal5623
@prerakagarwal5623 2 жыл бұрын
You are doing literally a very good job. I got to understand many concepts easily after watching your videos. Trees are very well explained. Many Thanks.
@anuragmalviya2397
@anuragmalviya2397 2 жыл бұрын
Bhaiya ki knowledge, video uploading me consistency, or way of explanation top notch hai!🔥🔥🔥
@VikrantK-c3j
@VikrantK-c3j 4 ай бұрын
Totally agreed
@kritarthtripathi9793
@kritarthtripathi9793 2 жыл бұрын
Best DSA course and consistency ++...Thank u so much for your effort❤
@RohitKumar-lt2bo
@RohitKumar-lt2bo 7 ай бұрын
Q1 TC = O(n^2) SC = O(1) Q1(if hashmap is used), use unordered_map TC = O(n) SC = O(n) Q2 TC = O(n^2) SC = O(1) Q2(if hashmap is used) TC = O(n) SC = O(n)
@deeplukhi3216
@deeplukhi3216 8 күн бұрын
hii are you complete this course
@Amaan-ji4su
@Amaan-ji4su Жыл бұрын
Best DSA course on youtube !
@ayushkiledar4730
@ayushkiledar4730 2 жыл бұрын
Awesome!! The best DSA anyone can teach!!
@chandrabhanbahetwar9638
@chandrabhanbahetwar9638 2 жыл бұрын
It is the best dsa course in the you tube bhaiya carry on we all are with you 🌹🌹
@iqfacts8647
@iqfacts8647 Жыл бұрын
Best dsa course I have ever seen
@ritendrasinghbhadauriya5751
@ritendrasinghbhadauriya5751 2 жыл бұрын
Sir apke efforts to wakai sir excellent and ek aur best cheez ki aap scratch se har cheez samjhate hai........and sir salute to your consistency........💯💯
@prabhatmishra6753
@prabhatmishra6753 2 жыл бұрын
Great Efforts Sir....I think who wants to learn tree this is the platform
@scoc55vora15
@scoc55vora15 Жыл бұрын
A Very WELL EXPLANATION wala Video and Insane amount of Effort of Love Bhaiya is clearly vivble and For that Again and Again Explanation Thank you bhaiya
@nishankdas1895
@nishankdas1895 Жыл бұрын
Amazing observation bro on the inorder to postorder question. I have never thought it that way.
@aaravanand2325
@aaravanand2325 3 ай бұрын
Sir ive been part of this course from the start And the amount of knowledge that i ve gained is just inexpressable When i saw that it was 7 am on morning and you were shooting i was forced to comment here Thankyou so much Whatever i am in DSA is due to you I owe you alot
@prashantbirajdar9271
@prashantbirajdar9271 2 жыл бұрын
wah bhaiyaa ..another an exciting session i understood every thing from this session thanks bhiyaa for providing free of cost DSA course...loves the most...content and your teaching technique is so optimistic...thanks again
@harpratapsinhnakoom3540
@harpratapsinhnakoom3540 2 жыл бұрын
words are not enough to express our gratitude towards you.. Thank you bhaiya
@ayushjangid5649
@ayushjangid5649 2 жыл бұрын
One of the best teacher || mentor. Thank you so much bhaiya for this course literally the best course.
@pavanmutalikdesai6611
@pavanmutalikdesai6611 2 жыл бұрын
Best explanation!!! You make solutions look so simple.
@KPCoder
@KPCoder 2 жыл бұрын
Thanks you sir, excellent content, no one can explain like you from basic 🙏 god bless you
@shaleenspeaks003
@shaleenspeaks003 2 жыл бұрын
The best best best and best course ever
@niteshkoli007
@niteshkoli007 2 жыл бұрын
ab ye question mai kabhi bhi nhi bhulne wala😁
@curiosityOnItsPeak
@curiosityOnItsPeak 2 жыл бұрын
I used to get scared from some of questions including these But now .....Huhh! . All thanks to you bhaiya
@AyushKumar-yu5tj
@AyushKumar-yu5tj 2 жыл бұрын
After this course Knowledge will be like knowledge= INT_MAX;
@rohanyadav2056
@rohanyadav2056 Жыл бұрын
Sir many many thanks to you You're an inspiration , I've referred this playlist to all my friends. Your dedication is next level sir
@Urahara25
@Urahara25 2 жыл бұрын
One suggestion bhaiya... We don't wanna get demotivated...so contest ke bhi solutions practice krwaiyega please......And company specific category bhi ki like kis site se kaun si kaun si company specific pdhna h... Interviewbit ,gfg,...etc...Amazon, Microsoft,google nd aur bhi
@RahulKumar-wt9qc
@RahulKumar-wt9qc 2 жыл бұрын
Shaandar video hai bhaiya 👍👍👍
@aashishrangdal9614
@aashishrangdal9614 2 жыл бұрын
Deadline Seriously Le Rhe Ho Kya Bhaiyya😂 Consistant Level OP😁🥰
@someshsangwan3768
@someshsangwan3768 2 жыл бұрын
Op consistency bhaiya 👍🔥🔥🔥
@suvigyabasnotra7378
@suvigyabasnotra7378 2 жыл бұрын
Can you give advice on what to do after seeing the solution of a problem you've never seen before and don't know how to code..?
@gauravverma4652
@gauravverma4652 2 жыл бұрын
in first question u used map for optimisation which have complexity O(logn), shouldn't we use unordered_map for O(1) complexity ??
@Coder_DhruvArora
@Coder_DhruvArora 2 жыл бұрын
Yes
@sahilchhabra2391
@sahilchhabra2391 2 жыл бұрын
bhai dono me O(1) hogi na. Map ki key already pata h toh value toh yuhi nikal jaegi aur mp.find() use krne ki need nhi kyuki map toh bana hi saari entries se hai, key toh pakka hogi hi.
@Coder_DhruvArora
@Coder_DhruvArora 2 жыл бұрын
@@sahilchhabra2391 I didn't got your point But even inserting into map also takes O(log n) So it definitely adds into time complexity
@sahilchhabra2391
@sahilchhabra2391 2 жыл бұрын
@@Coder_DhruvArora oh I forgot about the insertion complexity for ordinary map 😅, ya ya u got that right
@tanishagarwal5992
@tanishagarwal5992 Жыл бұрын
Basically if there are two equal elements in the inorder array , then it won't work and the testcases also are updated now, so the small change will be instead of looking in the entire inorder array, look in the part from instart to inend.
@rishiagarwal813
@rishiagarwal813 11 ай бұрын
bro 65th lecture ke bad GitHub par code links nhi hai ky ??
@aishwaryaporwal2321
@aishwaryaporwal2321 2 жыл бұрын
I just solving this question from ur DSA sheet n got this video notification ♥️♥️💯
@harshalpatil6482
@harshalpatil6482 5 ай бұрын
east or west babbar bhaiyya best
@shivkumar-og4ow
@shivkumar-og4ow 2 жыл бұрын
thank you bhaiya .. you are doing regularly hardwork to complete this course .. bahut bahut dhanybad.. ❤💘💘💘💘
@rohitrohra7553
@rohitrohra7553 Жыл бұрын
u make everything simple
@simplesolutions2621
@simplesolutions2621 2 жыл бұрын
Love _Consistency_ Babbar!
@ziyadauti3676
@ziyadauti3676 10 ай бұрын
Best explanation compared to others...!
@ankitgaur7428
@ankitgaur7428 2 жыл бұрын
Bhai Lecture 66 onwards code ko github mai push kyo nhi kar rhe ho? Repo se code samajna easy rehta hai. during videos hum code samaj sakte and then after completion of video hum code repo se notedown kar sakte hai. so pls push code from lecture 66 onwards in github repo.
@fahadnazir8924
@fahadnazir8924 Жыл бұрын
is Source-code of lecture 66 onwards available anywhere ?
@shrajangupta8206
@shrajangupta8206 Жыл бұрын
did you got any sourse where codes are there this lecture onwards?
@bishalchatterjee745
@bishalchatterjee745 2 жыл бұрын
kabhi kabhi lagta hain humse to jyada app mehenat karte hain bhaiay...!!
@rishabhjain7838
@rishabhjain7838 2 жыл бұрын
Dedication 😱💯💯
@keshavgambhir9894
@keshavgambhir9894 2 жыл бұрын
Present bhaiya Consistency op 🔥🔥🔥 Commenting for better reach
@prateeksharma3680
@prateeksharma3680 2 жыл бұрын
Attendance marked 👍👍👍 consistency 🔥🔥🔥
@Sam-rz5hw
@Sam-rz5hw 2 жыл бұрын
bhaiya aap best ho
@AahanRoy-l1i
@AahanRoy-l1i 22 күн бұрын
bhaiya, we can also solve it using unordered map, which can reduce the TC to O(n).
@shobhit9316
@shobhit9316 9 ай бұрын
In these questions, maps is useful in cases that have no equal values of nodes. but if there are... then you've to go for the first approach whose TC is o(n^2). Correct me if I'm wrong If you're trying with maps and gfg is not accepting, do it by the 1st approach
@VivekSharma-lr7kx
@VivekSharma-lr7kx 4 ай бұрын
use map of int ,queue insted
@rashmi_gaur
@rashmi_gaur 2 жыл бұрын
Awesome Explanation!
@utkarshsingh1457
@utkarshsingh1457 2 жыл бұрын
consistency op... Thanks for the beautiful content...Just enjoyed going through the lectures one by one... 😁
@deepak44222
@deepak44222 Жыл бұрын
mehnat lag raha hai bhai tum enjoy kaise kar le rahe ho.🥺🥺🥺🥺
@ShailendraSingh-ob7rp
@ShailendraSingh-ob7rp 2 жыл бұрын
Thank you bhaiya Maza aa gya questions solve krke ✌️✌️
@dewanshpatle9056
@dewanshpatle9056 2 жыл бұрын
Best course ever consistency++;
@muhammadsuleman8936
@muhammadsuleman8936 Жыл бұрын
Lecture was amazing brother
@yourkp
@yourkp 7 ай бұрын
Updated map solution for question - Construct Tree from Inorder & Preorder Intuition - Use Queue inside map to store the duplicates in the tree. class Solution{ public: void createMap(int in[], int n, map &nodeToIndex){ for (int i=0; i= n || inOrderStart > inOrderEnd){ return NULL; } //storing the node of preOrder (NLR) int element = pre[index++]; Node* root = new Node(element); //find the node in inorder (LNR) int position = nodeToIndex[element].front(); nodeToIndex[element].pop(); //recursive call for left and right root->left = solve(in, pre, n, index, inOrderStart, position-1, nodeToIndex); root->right = solve(in, pre, n, index, position+1, inOrderEnd, nodeToIndex); return root; } Node* buildTree(int in[],int pre[], int n) { int preOrderIndex = 0; map nodeToIndex; createMap(in, n, nodeToIndex); Node* ans = solve(in, pre, n, preOrderIndex, 0, n-1, nodeToIndex); return ans; } };
@siddharthyadav1885
@siddharthyadav1885 Жыл бұрын
great work and effort
@aparnamanna1369
@aparnamanna1369 2 жыл бұрын
Bhaiya consistency
@yashgupta4866
@yashgupta4866 2 жыл бұрын
Present bhaiya Consistency OP
@harshpandey4190
@harshpandey4190 Жыл бұрын
Thankyou So much bhaiya going great
@RohitKumar-dy2gc
@RohitKumar-dy2gc Жыл бұрын
you made me feel the traversal of tree
@shashanksingh4968
@shashanksingh4968 2 жыл бұрын
consistency++. PBC on the go.
@arjunrai8126
@arjunrai8126 2 жыл бұрын
Which company are you in, I mean how are u managing preparation and job?
@anandprateekbaranwal8275
@anandprateekbaranwal8275 2 жыл бұрын
Present bhaiya 🙋🏻‍♂️
@AA-wy9vw
@AA-wy9vw 2 жыл бұрын
Loving the series!!
@SanjuJana-pj6pn
@SanjuJana-pj6pn Жыл бұрын
Thank you sir 😊
@shivanshsah
@shivanshsah 7 ай бұрын
If you are reading this comment so I want to tell you that you have not provided the code in github from lecture 66
@abhayvarshney2993
@abhayvarshney2993 4 ай бұрын
Any reason for that?😢
@ritikamehta9791
@ritikamehta9791 2 жыл бұрын
Great consistency sir💯💯. Thank youu vry much!!
@satwiksharma4359
@satwiksharma4359 2 жыл бұрын
Great series , very helpful .
@himanshukashyap8894
@himanshukashyap8894 2 жыл бұрын
keep growing bhaiya. You do wonderful for us
@HarshJaiswal-v2f
@HarshJaiswal-v2f 9 ай бұрын
code link from 66 lecture to end is not available sir , plzz upload the link the of code link. thank you from the bottom of my heart sir for making a beautiful series for us 😍😍
@vanshgawra
@vanshgawra 2 жыл бұрын
I think if we use unordered map instead of map then our time complexity will be more better as it have T.C of O(1)
@roshangupta629
@roshangupta629 Жыл бұрын
NO bro, if we use map then if any number is repeating then we won't be able to make right tree.
@WizBoyYt
@WizBoyYt Жыл бұрын
@@roshangupta629 but what will it effect? repeation se kya hoga usme ye set thodi h
@tarakmheta8856
@tarakmheta8856 Жыл бұрын
we can use mutlimap instead of map here@@roshangupta629
@Harry-ju9nv
@Harry-ju9nv 2 жыл бұрын
bhaiya bhut badia padate hoo aap
@daipayannit-s415
@daipayannit-s415 Жыл бұрын
Commenting for better reach !!
@ani68
@ani68 2 жыл бұрын
Was waiting for this one......💯💯💯💯
@utkarshverma8773
@utkarshverma8773 2 жыл бұрын
ULTIMATE CONTENT
@ekanshsharma1309
@ekanshsharma1309 Жыл бұрын
Simply Love You Bhaiya 💗💗
@adarshparitosh5870
@adarshparitosh5870 2 жыл бұрын
Thank you so much bhaiya, before it I have been read 2,3 time but my concept was not clear but in first attempt I got 100℅ understanding of construct tree, ab mai DS se diprate ni ho rha😃ni to 4th sem me aa kar lgta tha khi CSE le kar galti to ni kr diye...
@mokshjain4985
@mokshjain4985 Ай бұрын
Great Work👋👋
@SanjeevChaube
@SanjeevChaube Жыл бұрын
bhaiya bhut axcha samjhate ho
@KACodes
@KACodes 2 жыл бұрын
Ajeeee....mai Keya maza agaya
@faizanalam8360
@faizanalam8360 2 жыл бұрын
Loved your efforts. Thank you bhaiya
@kunalbhika6424
@kunalbhika6424 7 ай бұрын
Great lecture as always😍
@VivekSharma-lr7kx
@VivekSharma-lr7kx 4 ай бұрын
# for those who stuck in test case 53 # there are dublicate values use map below is full code:- ---------------------------------------------------------------------------------- class Solution{ public: int find(int in[],int n,int element){ for(int i=0;iend || ind >=n) return NULL; int element = pre[ind++]; Node* root=new Node(element); // int pos=find(in,n,element); int pos = mp[element].front(); mp[element].pop(); root->left=make(in,pre,n,ind,start,pos-1,mp); root->right = make(in,pre,n,ind,pos+1,end,mp); return root; } public: Node* buildTree(int in[],int pre[], int n) { map mp; for(int i=0;i
@abhishekkumar-mp6no
@abhishekkumar-mp6no 2 жыл бұрын
bhaiya maja aa gaya
@7u5h42
@7u5h42 2 жыл бұрын
🙌🙌 consistency OP
@parassetia4964
@parassetia4964 2 жыл бұрын
Lot of love to you bhaiya, hope you are well and fine. Just waiting for graphs and dp too😅
@laksheybanga8106
@laksheybanga8106 2 жыл бұрын
Mzaa aa rha h bhaiyaaa 💕❤️
@sukhjitsingh959
@sukhjitsingh959 Жыл бұрын
keep coding and sharing errors as well as solutions to the error
@shekharsuman3219
@shekharsuman3219 2 жыл бұрын
Bhaiya keep inspiring us we r with u
@janvi_jindal05
@janvi_jindal05 2 жыл бұрын
you are the best bhai....
@chiragyadav5467
@chiragyadav5467 2 жыл бұрын
love bhaiya is best
@amishapandey6875
@amishapandey6875 Жыл бұрын
Really THANKFULL!
@PRIYANSHUKUMAR-un9zu
@PRIYANSHUKUMAR-un9zu 2 жыл бұрын
Present bhaiya🔥❤
@techeasy602
@techeasy602 2 жыл бұрын
Present Bhaiya ❤️
Lecture 67: Minimum Time to BURN the Entire Binary Tree || C++ Placement Series
28:28
Молодой боец приземлил легенду!
01:02
МИНУС БАЛЛ
Рет қаралды 1,9 МЛН
Players push long pins through a cardboard box attempting to pop the balloon!
00:31
How To Choose Mac N Cheese Date Night.. 🧀
00:58
Jojo Sim
Рет қаралды 88 МЛН
ASHNEER GROVER GOT ROASTED BY SALMAN KHAN!
13:08
Thugesh Unfiltered
Рет қаралды 1 МЛН
Lecture 64: Binary Tree FAANG Interview Questions || Part-2
1:11:31
CodeHelp - by Babbar
Рет қаралды 399 М.
AIR 6 vs AIR 600 after 6 years of graduating IIT
1:12:56
Harkirat Singh
Рет қаралды 17 М.
Lecture 52: Clone a Linked List with Random Pointers || C++ Placement Course
55:08