Binary Trees in Java 2

Binary Trees in JavaWelcome 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

17 thoughts on “Binary Trees in Java 2”

  1. 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!

  2. Line
    253 parent.rightChild = focusNode.leftChild;

    Shouldn’t it be:

    parent.rightChild = focusNode.rightChild;

    (As focusNode.leftChild is null )?

    1. I meant:
      Line 274 (As focusNode.leftChild is null )..

      Shouldn’t it be:

      parent.rightChild = focusNode.rightChild;

  3. 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

  4. 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.

  5. 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

  6. 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!

    1. 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

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

    1. 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.

  8. 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.

Leave a Reply

Your email address will not be published. Required fields are marked *