+ Reply to Thread
Results 1 to 10 of 10

Thread: Need help with binary trees.

  1. #1
    Newbie Daskill is an unknown quantity at this point
    Join Date
    Dec 2008
    Posts
    24

    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. #2
    Super Moderator WingedPanther has much to be proud of WingedPanther has much to be proud of WingedPanther has much to be proud of WingedPanther has much to be proud of WingedPanther has much to be proud of WingedPanther has much to be proud of WingedPanther has much to be proud of WingedPanther has much to be proud of WingedPanther has much to be proud of WingedPanther's Avatar
    Join Date
    Jul 2006
    Age
    36
    Posts
    11,684
    Blog Entries
    57

    Re: Need help with binary trees.

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

  3. #3
    Newbie Daskill is an unknown quantity at this point
    Join Date
    Dec 2008
    Posts
    24

    Re: Need help with binary trees.

    No, just a binary tree.

  4. #4
    CPD
    CPD is offline
    Learning Programmer CPD is on a distinguished road
    Join Date
    Nov 2008
    Posts
    57

    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.

  5. #5
    Newbie Daskill is an unknown quantity at this point
    Join Date
    Dec 2008
    Posts
    24

    Re: Need help with binary trees.

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

  6. #6
    Super Moderator WingedPanther has much to be proud of WingedPanther has much to be proud of WingedPanther has much to be proud of WingedPanther has much to be proud of WingedPanther has much to be proud of WingedPanther has much to be proud of WingedPanther has much to be proud of WingedPanther has much to be proud of WingedPanther has much to be proud of WingedPanther's Avatar
    Join Date
    Jul 2006
    Age
    36
    Posts
    11,684
    Blog Entries
    57

    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.
    CodeCall Blog | CodeCall Wiki | Shareware
    Programming is a branch of mathematics.
    My CodeCall Blog | My Personal Blog

  7. #7
    Newbie Daskill is an unknown quantity at this point
    Join Date
    Dec 2008
    Posts
    24

    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.

  8. #8
    Super Moderator WingedPanther has much to be proud of WingedPanther has much to be proud of WingedPanther has much to be proud of WingedPanther has much to be proud of WingedPanther has much to be proud of WingedPanther has much to be proud of WingedPanther has much to be proud of WingedPanther has much to be proud of WingedPanther has much to be proud of WingedPanther's Avatar
    Join Date
    Jul 2006
    Age
    36
    Posts
    11,684
    Blog Entries
    57

    Re: Need help with binary trees.

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

  9. #9
    Newbie Daskill is an unknown quantity at this point
    Join Date
    Dec 2008
    Posts
    24

    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?

  10. #10
    Super Moderator WingedPanther has much to be proud of WingedPanther has much to be proud of WingedPanther has much to be proud of WingedPanther has much to be proud of WingedPanther has much to be proud of WingedPanther has much to be proud of WingedPanther has much to be proud of WingedPanther has much to be proud of WingedPanther has much to be proud of WingedPanther's Avatar
    Join Date
    Jul 2006
    Age
    36
    Posts
    11,684
    Blog Entries
    57

    Re: Need help with binary trees.

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

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

     

Similar Threads

  1. Computer Theory: Signed Integers
    By John in forum Tutorials
    Replies: 3
    Last Post: 11-30-2008, 09:00 AM
  2. Binary Trees in C
    By Salrandin in forum C and C++
    Replies: 4
    Last Post: 12-02-2007, 04:29 PM
  3. Binary, Decimal, Hex, the Manual way!!
    By TcM in forum Tutorials
    Replies: 22
    Last Post: 01-10-2007, 12:06 AM

Bookmarks

Bookmarks

     
        Algorithms and Data Structures

        Java tutorials

        Algorithms Forum

Posting Permissions

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