Results 1 to 3 of 3
  1. #1
    sim18 is offline Member
    Join Date
    Oct 2011
    Posts
    30
    Rep Power
    0

    Default Binary tree help please

    Hi, If I get given an array say [5,4,10,8,21,12,9,45,13,11,28]

    I have to draw the complete binary tree for that. How would I know what goes at the top of the tree or where to start?

    I have looked around and have found you go from left to right, could somebody check my answer please?
    Java Code:
     
       5
      / \
    4    10
         /  \
       8     21
        \    /  \
         9  12  45
                  /
                13
                /  \
               11  28
    Last edited by sim18; 12-05-2012 at 06:05 AM.

  2. #2
    wdh321 is offline Senior Member
    Join Date
    Aug 2011
    Posts
    116
    Rep Power
    0

    Default Re: Binary tree help please

    It depends if you want to create a Binary Tree or a Binary Search Tree. The main difference between the two is with the BST, nodes to the left are greater than those to the right. This allows the tree to be efficiently searched. A BST can can have many different variations, from a completely balanced tree to a completely unbalanced tree depending on the root node value.

  3. #3
    sim18 is offline Member
    Join Date
    Oct 2011
    Posts
    30
    Rep Power
    0

    Default Re: Binary tree help please

    I'm not sure it just says to draw that complete binary tree from the array. I then have to heapify the tree into a maximum heap. (I know how to do this) Then I will be inserting and removing nodes into the tree.

    I am just checking if the tree is correct to begin with.

    Thank you

Similar Threads

  1. binary tree q
    By stuckonjava in forum New To Java
    Replies: 6
    Last Post: 05-21-2012, 05:58 PM
  2. Binary tree
    By harmy in forum New To Java
    Replies: 1
    Last Post: 02-03-2012, 08:46 AM
  3. Binary Tree Help - Find the largest sub-tree
    By joshhazel in forum New To Java
    Replies: 2
    Last Post: 01-30-2012, 02:08 AM
  4. Replies: 0
    Last Post: 04-04-2010, 07:40 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •