Why is this channel so underrated?? You are an amazing teacher. I love how you enjoy every bit of it while teaching. I've been binge watching your playlists for around 5 hours at 2X today. I miss learning like this. Thanks for the efforts, Sir! :)
Glad to know that you liked the content and thank you for appreciating. I hope that you are watching till the end and trying to understand what, how, and especially why of the problem. If you like our efforts, will you like to write a few words about us here (www.quora.com/What-are-the-good-websites-to-learn-data-structures-and-algorithms ) Keep learning and keep loving Pepcoding😊
last one week se confuse or frustrated ghum reha tha Btree ke liye or yeha mere doubt solve hogye..........waah ........... ye hota hai asli content bakki toh bas ad krte rehte hai
Thankyou beta! I am glad you liked it. I hope that you are watching till the end and trying to understand what, how, and especially why of the problem. If you like our efforts, will you like to write a few words about us here (www.quora.com/What-are-the-good-websites-to-learn-data-structures-and-algorithms )
Sir, can you please tell me if there are any issues if I use this code. Thanks in advance static int idx = 1; public static Node constructTree(Node root, int[] arr){ if(root.data == -1){ return null; } Node l = new Node(arr[idx++],null,null); root.left= constructTree(l,arr); Node r = new Node(arr[idx++],null,null); root.right= constructTree(r,arr); return root; }
sir coding blocks mai prateek bhaiya se padha tha and aapne extra class li thi attend nahi kar paaya tha . mujhe nahi pata tha aap itna awsome padhate ho.
did anyone actually try to write the code and see if it works? cause it clearly doesn't! the array index needs to be incremented even when we are setting null. please at least mention the correction in the comment section.
idx++ has been done outside of the if-else statement, so it gets incremented in both the cases. This code works fine for me. please at least double-check before ranting!
its done already...it has to be done just once...its better to do it outside if else.....for easier tracking rather than doing it individually for both if part and else part..
- Make arr[0] as the root node and push in the stack with flag=1 - int i=0 // to traverse in the preorder path array - while the stack is not empty: - For stack top element - If flag =1 - i++ - increment the flag value of the stack top node - If arr[i] is not null then - connect arr[i] to the left of the stack top node - push pair(arr[i], 1) to the stack - else if flag = 2 - i++ - increment the flag value of the stack top node - If arr[i] is not null then - connect arr[i] to the right of the stack top node - push pair(arr[i], 1) to the stack - else if flag = 3 then pop the stack
Why is this channel so underrated?? You are an amazing teacher. I love how you enjoy every bit of it while teaching. I've been binge watching your playlists for around 5 hours at 2X today. I miss learning like this. Thanks for the efforts, Sir! :)
Glad to know that you liked the content and thank you for appreciating. I hope that you are watching till the end and trying to understand what, how, and especially why of the problem. If you like our efforts, will you like to write a few words about us here (www.quora.com/What-are-the-good-websites-to-learn-data-structures-and-algorithms )
Keep learning and keep loving Pepcoding😊
Bhai yahi sawal muzi bhi padta hai har roj
awesome! Thank you so much, there are very less tutorials on net which focus ds on java
Glad it was helpful!
one more correction in the code. whenever we are checking if(arr[idx]!=null), add one more check that if idx
Thank you so much Sir the way you teach in a calm manner is so soothing and I just love your content thank you may God bless you
last one week se confuse or frustrated ghum reha tha Btree ke liye or yeha mere doubt solve hogye..........waah ........... ye hota hai asli content bakki toh bas ad krte rehte hai
Thank You So Much Sumeet Sir...............................🙏🏻🙏🏻🙏🏻🙏🏻🙏🏻🙏🏻
you are amazing sir & your way of teaching & explaination is superb thankyou so much sir😍🤩
Thanku sir
you makes the things easy
It is my first time i learnt binary tree
and it was awesome to learn from you
Thankyou beta!
I am glad you liked it. I hope that you are watching till the end and trying to understand what, how, and especially why of the problem.
If you like our efforts, will you like to write a few words about us here (www.quora.com/What-are-the-good-websites-to-learn-data-structures-and-algorithms )
Sir, can you please tell me if there are any issues if I use this code. Thanks in advance
static int idx = 1;
public static Node constructTree(Node root, int[] arr){
if(root.data == -1){
return null;
}
Node l = new Node(arr[idx++],null,null);
root.left= constructTree(l,arr);
Node r = new Node(arr[idx++],null,null);
root.right= constructTree(r,arr);
return root;
}
sir coding blocks mai prateek bhaiya se padha tha and aapne extra class li thi attend nahi kar paaya tha . mujhe nahi pata tha aap itna awsome padhate ho.
Koi nh beta, ab yha se pdd lo. If you like our efforts, will you like to review us here - g.page/Pepcoding/review?rc
@@Pepcoding done sir
How to create a binary tree non recursively using linked list and stack ? inputs to be taken from user. Hope you will reply
Excellent
you are gifted!
please can you give c++ codes also
Gazab explanation sir
public static class Pair {
Node node;
int state;
public Pair(Node node, int state) {
this.node = node;
this.state = state;
}
}
public static Node takeInput(Integer arr[]) {
if (arr.length = 3) st.pop();
} else {
Node nn = new Node(arr[i]);
if (st.peek().state == 1) st.peek().node.left = nn;
else if (st.peek().state == 2) st.peek().node.right = nn;
st.peek().state++;
if (st.peek().state >= 3) st.pop();
st.add(new Pair(nn, 1));
}
}
return root;
}
Sir one thing I want to ask
Can we take user input for left and right nodes of BINARY TREE
yes
sir apki trees ki level 2 ki playlist hai to plz share your link nahi mil rahi playlist mujhe
sir why don t we use linked list in constructing trees ,becoz in arrays memory is wasted a lot?
you can use linked list
Just wanted to know....does this method work only for BST ?
Nahi beta, thora alg h BST ka.
@@Pepcoding iss method se hum sirf pre order traversal ki help se tree construct kr skte hain na sir?
Sir please upload the question set of trees on the pepcoding website. There are no questions of trees available.
hanji, abhi content pichle 3 din se nya nahi bna hai. ye old upload ho rha hai. wo question bhi dalte hain soon
@@Pepcoding Ok sir. Very helpful videos. Thank you sirr!!
We are glad. Keep watching.
Sir cpp me NULL nahi kr sakte toh kya karen usme
java use kare
Sir ye opps bahut prblm create ker rha hai sangh nhi aa rha hai
Class object, constructor, this bs itna hi use hora h ye main oops thori h uper layer h.
@@anjneykumarsingh4461 ha bro aa gya sab maine khud se meditate kiya to ekdum clear ho gya
did anyone actually try to write the code and see if it works? cause it clearly doesn't! the array index needs to be incremented even when we are setting null.
please at least mention the correction in the comment section.
idx++
has been done outside of the if-else statement, so it gets incremented in both the cases.
This code works fine for me.
please at least double-check before ranting!
its done already...it has to be done just once...its better to do it outside if else.....for easier tracking rather than doing it individually for both if part and else part..
- Make arr[0] as the root node and push in the stack with flag=1
- int i=0 // to traverse in the preorder path array
- while the stack is not empty:
- For stack top element
- If flag =1
- i++
- increment the flag value of the stack top node
- If arr[i] is not null then
- connect arr[i] to the left of the stack top node
- push pair(arr[i], 1) to the stack
- else if flag = 2
- i++
- increment the flag value of the stack top node
- If arr[i] is not null then
- connect arr[i] to the right of the stack top node
- push pair(arr[i], 1) to the stack
- else if flag = 3 then pop the stack