Welcome to my 2nd video on Binary Trees in Java. If you haven’t seen part 1, definitely watch it first or this will be confusing binary tree in Java.
In this part of the tutorial, I will take you step-by-step through the process of deleting nodes in a binary tree. This topic seems to be confusing to many people. I personally prefer to build trees with the builder design pattern like I showed here Encapsulate Composite with Builder, but it is also important to understand the basics of the binary tree.
If you like videos like this, it helps to tell Google+ with a click here [googleplusone]
Code From the Video
Binary Trees in Java : BinaryTree.java
Hi Derek,
I really enjoy your tutorials. They are the best that I have ever seen. Thank you very much for making those videos, which are super helpful!
I wonder in the near future if you plan to do some tutorials on java generics.
Thanks again!
Thank you 🙂 Yes I will fill in all of the topics I skipped over in the original Java tutorial. I’ll cover everything by the end
Line
253 parent.rightChild = focusNode.leftChild;
Shouldn’t it be:
parent.rightChild = focusNode.rightChild;
(As focusNode.leftChild is null )?
I meant:
Line 274 (As focusNode.leftChild is null )..
Shouldn’t it be:
parent.rightChild = focusNode.rightChild;
I went back and checked the code and you are correct. Sorry about the error. I fixed it. Thank you very much for pointing that out 🙂
Hi Derek,
Thank you so much for your excellent work!
The question I have is related to your code but not really related to the BinaryTree topic. I run your code on Eclipse and get error of “coudn’t find the main class, program exit”. It happened to several classes of mine recently and I don’t know why. Can you help me with this?
Thank you!
PJ
Hi PJ,
Check out Install Eclipse for Java. You need to save the code in the source folder in the project explorer.
Good day Derek,
Thank you so much for your wonderful tutorial!
I have a favor to ask about tutorial about a B-Tree or B+Tree?
If you can help me about it.
You’re very welcome 🙂 Thank you. Yes I will make an advanced algorithm tutorial very soon.
Great tutorial, but when you add the numbers in an odd order such as 80,25,40,45,75,2 and try to print the traverse in order it comes out as 25,2,40,45,75,2
I’ll take a look at that. Thank you for pointing it out
Hi Derek,
Your tutorials are excellent, explanatory and free..I am the #1 fan of your presentation style!
As I’m java beginner I face with a lot of questions, would you mind give me your email.
Thank you for your help!
Thank you 🙂 The best way to get me is to leave a message here, through a YouTube PM, or through a Google+ PM. My email account has been messed up. I get over 1000 emails a day. I’m always happy to help 🙂
Derek
Thank you for your quick reply, you’re awesome!
I have completed all your java video and java algorithms tutorials but i don’t know which one should i study next. Can you write me which order i have to follow, i have planned to finish all your video tutorials.
I am addicted to your tutorials!
essey
Thank you 🙂 They were made to watch in this order : Design Patterns, UML, Object Oriented Design, Refactoring, but you can do them in any order for the most part.
Excellent tutorial! However, I noticed that in your delete function you don’t check for a null root before entering the while loop. This can lead to an infinite loop if the user tries to delete any node while the list is empty.
I just inserted the simple
if (root == null)
{
return false;
}
in-between lines 171 and 175.
Thanks for the input. Sorry I missed that. i was writing out of my head.