Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 4 of 4

Thread: Building a binary tree

  1. #1
    Junior Member
    Join Date
    Apr 2020
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Post Building a binary tree

    Hello everyone,

    I'm working on a lab and my implementation failed a test case for a binary tree algorithm. The output says:

    --------------------
    Test 5 failed!
    left: 3 2 -1 -1
    right: 1 -1 -1 -1
    --------------------

    This is the structure for the binary tree where my code failed but I don't know what the BT looks like based off of the integers in left and right. If you know how to translate this into a binary tree or if it's not even possible please let me know, thanks.

  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Building a binary tree

    Do you have an instructor that you could ask about your question?

    Where did that output come from?
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Junior Member
    Join Date
    Apr 2020
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Building a binary tree

    Yes I emailed him yesterday and the lab is due Sunday. He may not reply because it's the weekend and I'm on a time crunch to complete this. The output is from his test cases which display output which is the tree for the test that failed.

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Building a binary tree

    My guess is that the values: 1,2,3 are the leaves of the tree and the -1s are empty slot values from somewhere.
    A binary tree with those 3 values could have 1 and 3 as the left and right childern and 2 as the parent.

    I have no idea how that output is created.
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. (Binary Tree) Family tree - help with my addChild method
    By Pip_Squeak in forum What's Wrong With My Code?
    Replies: 5
    Last Post: March 26th, 2014, 07:52 AM
  2. Binary Search Tree inorder tree traversal
    By Maukkv in forum What's Wrong With My Code?
    Replies: 17
    Last Post: January 26th, 2013, 05:28 PM
  3. binary tree not building correctly
    By NCNerdGirl in forum What's Wrong With My Code?
    Replies: 1
    Last Post: February 21st, 2012, 12:24 PM
  4. Building a binary search tree
    By Herah in forum What's Wrong With My Code?
    Replies: 1
    Last Post: November 28th, 2011, 07:29 AM
  5. Data Structures(Binary Search Tree to AVL Tree)ASAP
    By jfAdik in forum Algorithms & Recursion
    Replies: 2
    Last Post: April 5th, 2010, 03:58 AM

Tags for this Thread