You just simplified the concept of bst deletion !!! Others just glorify the deletion as a complex 3 case problem and still keep you scared and confused . Yours give a life time intuition that stay for long time . I am wondering like why this problem didn't felt so simple before this video . Thank you !!
getSuccessor-methods while loop should check if temp.left is null instead of checking temp, that is: while(temp.left != null) instead of while(temp != null), otherwise there will be a nullPointerException when trying to delete a node that has two children. Otherwise, very helpful. Thankyou!
Hey. Nice Video. Could you please explain to me why you write node.right = delete(node.right,4) ? I dont really understand why you save the result in node.right. Also isnt it kind of bad to write bare number in code like the 4? Shouldnt that be successor.data? Or is it possible that the value of successor changes when i call the delete function again? Best regards
Hi, I agree with you. This was mistake done at my end. I've also pinned down it in my comment about it. You're right. It should be successor.data. when I realized this, video was already uploaded so could not change it.
Debugging helps you in understanding each line of code & data which is being processed. That's main reason for explaining this way. It helps even if you're beginners. But if you're good in it, please skip debugging & run the code :)
Hi, could you please paste your code & mention at which step, you're not getting correct results or facing issue. - Without checking code, it's difficult to check where you're facing the issue. Thanks.
Sorry for responding late. This is needed as we're solving two cases in this If - One when node is leaf node (node.left == null && node.right) - Second, when node has single child (either left or right) (node.left==null || node.right==null) will serve both purpose.
@@CodingSimplified i guess i need to watch it again then i will get it .... actually I'm beginner and yesterday i wasn't able to understand anything but today i am ...
@@aryanbisht7752 : I agree with you. This was mistake done at my end. I've also pinned down it in my comment about it, which is the first comment. You're right. It should be successor.data. when I realized this, video was already uploaded so could not change it.
Hi, I know it's too late, but if you want, we've launched site & for this problem, source code is present at : thecodingsimplified.com/delete-a-node-of-binary-search-tree/
the tree example that you have taken in the video is not correct, the values in left subtrees should be less than the root and values in right subtrees should be bigger than root value
Hi, where do you see issue. Looks like example is correct, where all value in left-Subtree are less than root & all values in right subtree are greater than root. - Could you please elaborate the point, where it's not correct so that I can check it further.
At [12.35]: It'll be 'node.right = delete(node.right, successor.data)'; rather than 'node.right = delete(node.right, 4)';
thanks for video. And in above there should not be node.right = (....) but only delete(node.right , successor.data);
exactly man, I was confusing, didn't think of checking comment first xd
You just simplified the concept of bst deletion !!! Others just glorify the deletion as a complex 3 case problem and still keep you scared and confused . Yours give a life time intuition that stay for long time . I am wondering like why this problem didn't felt so simple before this video . Thank you !!
Thanks for your nice feedback. Glad you liked it. Keep watching.
getSuccessor-methods while loop should check if temp.left is null instead of checking temp, that is: while(temp.left != null) instead of while(temp != null), otherwise there will be a nullPointerException when trying to delete a node that has two children.
Otherwise, very helpful. Thankyou!
That's right. Thanks for mentioning. Updated this at thecodingsimplified.com/delete-a-node-of-binary-search-tree/
Your teaching style is amazing. I've learned a lot about tree data structures from your videos. Thank you for your time and effort. 🙂👌
You're the man brother, after a few videos and an overwhelmed evening of relearning BSTs, makes SO much more sense.
Thanks for your nice feedback. Keep Watching.
Most precise level of teaching ...really amazing...because of your tutorial got to learn properly about Binary Search Tree..thanks!
Thanks Munazza. Glad to know it helped you.
I am really grateful to you. You saved me from a terrible exam. Virtual hugs!
Thanks for your nice feedback. Keep Watching.
Super great video!!! Finally able to learn deletion in bst after so much stress for not able to find reliable source 😇.
Keep it up Sir!!!!
Thanks. Keep Watching.
Please find the source code at: thecodingsimplified.com/delete-a-node-of-binary-search-tree/
thank you so much you are A great teacher this lesson helps me a lot
in the else part where you called delete function howcome your are sending 4 as a key value shouldnt be there .data ?
Works for most cases but fails when the key to be deleted is in the root node.
at 7:20 why is it return node instead of return temp
in the lines 47 to 51 whats thew pont of using if else as you r returning temp in either way
instead of 4 use successor .data it works
That's right. We've pinned this in comment as well. Thanks.
The video was very clear and nice I learnt a lot from your videos..Thanks
Thanks. Keep Watching.
Nice explanation,Debugging helps more to understand .thank you.
+vidya kamath Thanks. Keep Watching more tutorials.
This video is super helpful! Thank you!
Thanks for your nice feedback. Keep Watching.
Good and clear explanation.
Thanks for your nice feedback. Keep Watching.
Amazing explanation
please tell how to check if a tree is bst
Please check following. We've already covered this : ruclips.net/video/L2b3KQWIq_0/видео.html
Can we able to delete the root node using this code sir.
Hey. Nice Video. Could you please explain to me why you write node.right = delete(node.right,4) ?
I dont really understand why you save the result in node.right. Also isnt it kind of bad to write bare number in code like the 4? Shouldnt that be successor.data? Or is it possible that the value of successor changes when i call the delete function again?
Best regards
Hi, I agree with you. This was mistake done at my end. I've also pinned down it in my comment about it. You're right. It should be successor.data. when I realized this, video was already uploaded so could not change it.
great work sir thank you for this😍😍
thanks sir you are amazing
Thanks for your nice feedback. Keep Watching.
Thankyou so much for guidance!
Thanks for your nice feedback. Keep Watching.
why you debug instead of run the code.
Debugging helps you in understanding each line of code & data which is being processed. That's main reason for explaining this way. It helps even if you're beginners. But if you're good in it, please skip debugging & run the code :)
The debugging helps,....
Verbal explanation needs repair
I am implementing delete method in void and I am having a problem to delete node can you please check that.
Hi, could you please paste your code & mention at which step, you're not getting correct results or facing issue.
- Without checking code, it's difficult to check where you're facing the issue. Thanks.
@@CodingSimplified 1 import java.util.*;
class Node
{ int data;
Node left;
Node right;
public Node()
{ data=0;
left=null;
right=null;
}
public int getData()
{
return(data);
}
public Node getRight()
{ return(right); }
public Node getLeft()
{ return(left);
}
public void setData(int d)
{ data=d; }
public void setRight(Node n)
{ right=n; }
public void setLeft(Node n)
{
left=n;
}
}
class BinarySearchTree
{
Node root;
public BinarySearchTree()
{
root=null;
}
public boolean isempty()
{
if(root==null)
return true;
else
return false;
}
public void insert(int data)
{
if(root==null)
{
Node n=new Node();
n.setData(data);
root=n;
}
else{
insert(root,data);
}
}
public void insert(Node s,int value )
{
Node n=new Node();
if(values.getData())
{
search(s.getRight(),value);
}
else
{
search(s.getLeft(),value);
}
}
public void deleteNode(int data)
{
deleteNode(root,data);
}
public void deleteNode(Node root,int value)
{
if(root==null)
{
System.out.println("Data not present to delete");
}
else if(value>root.getData())
{
//root=root.getRight();
deleteNode(root.getRight(),value);
}
else if(value
In this deleteNode function not able to delete any value
what is the need of if(node.left==null || node.right==null)?.can i write if(node.left==null && node.right==null){ return null; }
Sorry for responding late. This is needed as we're solving two cases in this If
- One when node is leaf node (node.left == null && node.right)
- Second, when node has single child (either left or right)
(node.left==null || node.right==null) will serve both purpose.
Hindi explanation of same problem - ruclips.net/video/XPGU8oFpJVA/видео.html
Thanks bro ..
Thanks Amit.
I wonder why you put (4). What if you don't know the leftmost node of the right node. Kindly explain
I would send successor.data
@@shariqshoaib3207 dude...thanks...tons of respect
That's right. I was checking this video again & found out this. Silly Mistake. It should be successor.data. Not sure how to edit on live video.
Have you done any videos on balancing a tree?
Not yet, but we'll create soon on AVL balancing & Red-Black Tree. Thanks
I hope you make it soon please we need it
king!!!!!!!!!!!!!!!
Thanks.
great video, make more.
Thanks. Please watch other videos from playlist
why too hard?
public Node deleteNode(Node node, int value) {
if (node == null)
return null;
if (node.getValue() == value)
return null;
if (value < node.getValue())
node.setLeft(deleteNode(node.getLeft(), value));
else
node.setRight(deleteNode(node.getRight(), value));
return node;
}
cause if you delete top of the tree, you will lose the top ,and it'll be 2 trees. lol...
too complicated
Hi, the problem is definitely tough. BTW at what point you're stuck. We can try to help you.
I didn't understand ☹️
Hi Adarsh, could you please explain what you're not understanding so that we can help you.
@@CodingSimplified i guess i need to watch it again then i will get it .... actually I'm beginner and yesterday i wasn't able to understand anything but today i am ...
@@coderbuddy3875 That's nice.
Great
Thanks. Keep Watching.
I think this is wtong
Hi Aryan, could you please elaborate what's wrong so that we can update accordingly. Thanks.
Node.right=delete(node.right,4);
It should be :
delete(node.right,successor.data);
@@aryanbisht7752 : I agree with you. This was mistake done at my end. I've also pinned down it in my comment about it, which is the first comment. You're right. It should be successor.data. when I realized this, video was already uploaded so could not change it.
NO ME LA CONTEEEEEEEEESPHITE
Can u provide me the source code?
Hi, I know it's too late, but if you want, we've launched site & for this problem, source code is present at : thecodingsimplified.com/delete-a-node-of-binary-search-tree/
the tree example that you have taken in the video is not correct,
the values in left subtrees should be less than the root and values in right subtrees should be bigger than root value
Hi, where do you see issue. Looks like example is correct, where all value in left-Subtree are less than root & all values in right subtree are greater than root.
- Could you please elaborate the point, where it's not correct so that I can check it further.