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

preview_player
Показать описание
In this Video, we are going to solve TREE Important Interview Questions.

There is a lot to learn, Keep in mind “ Mnn bhot karega k chor yrr apne se nahi hoga ya maza nahi aara, Just ask 1 question “ Why I started ? “

Questions Links:



Do provide you feedback in the comments, we are going to make it best collectively.

Connect with me here:

Telegram Group Link: Love Babbar CODE HELP

Intro Sequence: We have bought all the required Licenses of the Audio, Video & Animation used.

Timestamps:

00:00 - Question 1
02:53 - Approach
11:05 - Code
22:38 - Question 2
23:40 - Approach
27:20 - Code

#DSABusted #LoveBabbar
Рекомендации по теме
Комментарии
Автор

30:15 You clearly have a strong understanding about where the students could get stuck. Much love

anuragpandey
Автор

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<=inorderEnd ;i++){
if(in[i]==element){
return i ;
}
}
return -1 ;
}
Node* solve(int in[], int pre[], int &index, int inorderStart, int inorderEnd, int n){
if(index>=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 ;
}

topshorts
Автор

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.

anmol
Автор

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.

govindsuryavanshi
Автор

Best course!
Best teacher!
*Best time to learn!* 🔥

simplesolutions
Автор

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 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<=e;i++)
{
if(in[i]==x)
return i;
}
}😇

aayushiagarwal
Автор

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.

prerakagarwal
Автор

Best DSA course and consistency ++...Thank u so much for your effort❤

kritarthtripathi
Автор

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

prashantbirajdar
Автор

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

rampratapmishra
Автор

Great Efforts Sir....I think who wants to learn tree this is the platform

prabhatm
Автор

Awesome!! The best DSA anyone can teach!!

ayushkiledar
Автор

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.

ankitgaur
Автор

Bhaiya ki knowledge, video uploading me consistency, or way of explanation top notch hai!🔥🔥🔥

anuragmalviya
Автор

It is the best dsa course in the you tube bhaiya carry on we all are with you 🌹🌹

chandrabhanbahetwar
Автор

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

scocvora
Автор

Amazing observation bro on the inorder to postorder question. I have never thought it that way.

nishankdas
Автор

Ek ek chize achche se explain kiya apne great bhaiya 💯

adityacreator
Автор

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)

vinayakgarg
Автор

Best explanation!!! You make solutions look so simple.

pavanmutalikdesai