Closed Thread
Results 1 to 10 of 10

Thread: Need help with binary trees.

  1. #1
    Daskill is offline Newbie
    Join Date
    Dec 2008
    Posts
    24
    Rep Power
    0

    Need help with binary trees.

    I've got an exercise where I have a set of numbers for which I have to draw the corresponding binary tree.

    However I don't know how to draw the binary tree for them. Is there a specific order that they're supposed to go in?

    I know that in binary search trees, you have to put all the numbers less than the root in the left sub-tree and all the numbers greater than the root in the right sub-tree, but I don't know how it works in a regular old binary tree.

    Can anyone help me?

  2. CODECALL Circuit advertisement
    Join Date
    Always
    Posts
    Many

     
  3. #2
    Join Date
    Jul 2006
    Posts
    16,478
    Blog Entries
    75
    Rep Power
    143

    Re: Need help with binary trees.

    I would assume they want either a binary search tree or a balanced binary search tree.
    Programming is a branch of mathematics.
    My CodeCall Blog | My Personal Blog

  4. #3
    Daskill is offline Newbie
    Join Date
    Dec 2008
    Posts
    24
    Rep Power
    0

    Re: Need help with binary trees.

    No, just a binary tree.

  5. #4
    CPD
    CPD is offline Learning Programmer
    Join Date
    Nov 2008
    Posts
    57
    Rep Power
    12

    Re: Need help with binary trees.

    The structure of the tree depends on how the numbers are inserted. If this isn't a binary search tree then you need to know the algorithm for inserting before you can draw any example trees.

  6. #5
    Daskill is offline Newbie
    Join Date
    Dec 2008
    Posts
    24
    Rep Power
    0

    Re: Need help with binary trees.

    It just gives me a set of numbers and says "draw the corresponding complete binary tree".

  7. #6
    Join Date
    Jul 2006
    Posts
    16,478
    Blog Entries
    75
    Rep Power
    143

    Re: Need help with binary trees.

    Are you allowed to put the numbers in any order, does the tree have to be balanced, etc? As stated, you could treat it like a linked list, only using the right links.
    Programming is a branch of mathematics.
    My CodeCall Blog | My Personal Blog

  8. #7
    Daskill is offline Newbie
    Join Date
    Dec 2008
    Posts
    24
    Rep Power
    0

    Re: Need help with binary trees.

    Well, that's the problem, I don't know, it just says, "draw the corresponding complete binary tree". I don't know if I should insert them as I would in a binary search tree, I'm not sure if it has to be balanced, but I do know that the next thing I have to do is heapify it.

  9. #8
    Join Date
    Jul 2006
    Posts
    16,478
    Blog Entries
    75
    Rep Power
    143

    Re: Need help with binary trees.

    So build the binary tree with that in mind.
    Programming is a branch of mathematics.
    My CodeCall Blog | My Personal Blog

  10. #9
    Daskill is offline Newbie
    Join Date
    Dec 2008
    Posts
    24
    Rep Power
    0

    Re: Need help with binary trees.

    How? Where do the numbers go? Do I do it just as a heap where the smallest number goes at the top? Is there a difference between a complete binary tree and a heap?

  11. #10
    Join Date
    Jul 2006
    Posts
    16,478
    Blog Entries
    75
    Rep Power
    143

    Re: Need help with binary trees.

    Have a look at this article: Binary heap - Wikipedia, the free encyclopedia
    Programming is a branch of mathematics.
    My CodeCall Blog | My Personal Blog

Closed Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Binary trees structure comparison
    By Slammerek in forum C and C++
    Replies: 2
    Last Post: 07-14-2011, 07:55 AM
  2. Traversal of binary search trees
    By kakariki in forum General Programming
    Replies: 3
    Last Post: 07-14-2011, 07:52 AM
  3. [Help] MFC maze (Binary Trees)
    By Beeko in forum C and C++
    Replies: 12
    Last Post: 01-04-2011, 10:21 PM
  4. Balancing Binary Search Trees
    By Daskill in forum General Programming
    Replies: 6
    Last Post: 12-08-2008, 11:46 AM
  5. Binary Trees in C
    By Salrandin in forum C and C++
    Replies: 4
    Last Post: 12-02-2007, 02:29 PM

Tags for this Thread

Bookmarks

Posting Permissions

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