Thanks bhaiya... I was actually thinking and trying the code with iterative approach for the last 2 days.I have somewhat reached but still i was not able to complete the code. But now it is crystal clear.. The gem for iterative approach is the current and parent pointer ( i was coding in C ) .. Thanks a lot .
When insert an element already present inside the tree in this case the iteration logic provided in this video was not pass all test case of GFG, was it happened with others?
Use this iterative code to pass all testcases of GFG: Node insert(Node root, int Key) { // your code here //Recursive method is commented out, iterative method is uncommented currently // if (root == null){ // return new Node(Key); // } // if (root.data > Key){ // root.left = insert(root.left, Key); // }else if (root.data < Key){ // root.right = insert(root.right, Key); // } // return root;
Node newNode = new Node(Key); Node cur = root; Node parent = null; while (cur != null){ parent = cur; if (cur.data == Key) return root; //this line handles if K is already present in BST if (cur.data > Key) cur = cur.left; else cur = cur.right; } if (parent == null) { return newNode; } else if (parent.data < Key){ parent.right = newNode; }else parent.left = newNode; return root; }
Bhaiya pls GROUPON sde intern ke preparation se related kisi se experience share krwa dijiye 🙏🙏🙏🙏🙏🙏 UA-cam pe Groupon ki prep ka koi content available nhi hai
where did i do wrong its been 25 min but i coudn't find it welcome if anybody give favor in it.. class Solution { // Function to insert a node in a BST. Node insert(Node root, int Key) { Node newnode = new Node(key); Node current = root; Node Parent = null; while(key != current.key){ Parent = current; if(key < current.key){ current = current.left; }else{ current = current.right; }if(Parent == null){ Parent = newnode; }elsif(key < Parent.key){ Parent.left = newnode; }else{ Parent.right = newnode; } return root; } }
Nice content thanks Bhaiya for uploading video more frequently
Thanks bhaiya... I was actually thinking and trying the code with iterative approach for the last 2 days.I have somewhat reached but still i was not able to complete the code. But now it is crystal clear.. The gem for iterative approach is the current and parent pointer ( i was coding in C ) .. Thanks a lot .
Love you bhaiya first
Please make a 60 roadmap on important DSA topics for DSA beginner to crack tech giant's like Microsoft Amazon level companies
Thanks bhaiya...for your uploading speed. ❤️
Thank you bhaiya ❤️
Bhaiya can you upload video on springboot briefly describing from interview perspective.Thanks for the amazing videos.love❤
Amazing explanation!
Best explaination
bhaiya please make detailed video on hackathons
Node insert(Node root, int Key) {
Node newnode = new Node(Key);
Node curr=root;
Node parent=null;
while(curr!=null){
parent=curr;
if(Key
Thank u bhaiya
Nice explanation sir😌
Nice explanation
When insert an element already present inside the tree in this case the iteration logic provided in this video was not pass all test case of GFG, was it happened with others?
Use this iterative code to pass all testcases of GFG:
Node insert(Node root, int Key) {
// your code here
//Recursive method is commented out, iterative method is uncommented currently
// if (root == null){
// return new Node(Key);
// }
// if (root.data > Key){
// root.left = insert(root.left, Key);
// }else if (root.data < Key){
// root.right = insert(root.right, Key);
// }
// return root;
Node newNode = new Node(Key);
Node cur = root;
Node parent = null;
while (cur != null){
parent = cur;
if (cur.data == Key) return root; //this line handles if K is already present in BST
if (cur.data > Key)
cur = cur.left;
else
cur = cur.right;
}
if (parent == null) {
return newNode;
}
else if (parent.data < Key){
parent.right = newNode;
}else parent.left = newNode;
return root;
}
Sir prepare will tell me whether recorder app is hybrid or not nebread
Bhaiya when can we expect this course to finish??and whats ur next plan after this DSA-one course?
please add some more videos on android development tutorials.
bhaiya what is your other source of income now ? k
nice sir
Bhaiya how long th is course will continue ❤️❤️
bhaiya can u plzz make a video on rabin karp and kmp pattern matching algo's with code i am finding it really difficult to understand😊😊
Replace x and key with Key
bhaiyya second code mei what is cur.key? if cur is a node type value then it shouldnt have an attribute named key right?
curr.data and parent.data aega vaha
Bhaiya flutter wali playlist start krona jaldi please
Bhaiya kabtak complete karbaoge DSA course ❤️
Please reply
Bhaiya pls GROUPON sde intern ke preparation se related kisi se experience share krwa dijiye 🙏🙏🙏🙏🙏🙏
UA-cam pe Groupon ki prep ka koi content available nhi hai
Python video bhaiya
can you please share code?
Node* insert(Node* root, int Key) {
// Your code here
if(root == NULL){
root = new Node(Key);
return root;
}
Node *curr = root, *parent = root;
while(curr != NULL){
parent = curr;
if(Key == curr->data){
return root;
}
else if(Key < curr->data){
curr = curr->left;
}
else{
curr = curr->right;
}
}
curr = new Node(Key);
if(Key < parent->data){
parent->left = curr;
}
else{
parent->right = curr;
}
return root;
}
where did i do wrong its been 25 min but i coudn't find it welcome if anybody give favor in it..
class Solution {
// Function to insert a node in a BST.
Node insert(Node root, int Key) {
Node newnode = new Node(key);
Node current = root;
Node Parent = null;
while(key != current.key){
Parent = current;
if(key < current.key){
current = current.left;
}else{
current = current.right;
}if(Parent == null){
Parent = newnode;
}elsif(key < Parent.key){
Parent.left = newnode;
}else{
Parent.right = newnode;
}
return root;
}
}
Bhaiya I am new or muje pata nhi hai ki DSA eitna hi hai
subs at the start are crazy🥲🥲