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?
I would assume they want either a binary search tree or a balanced binary search tree.
No, just a binary tree.
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.
It just gives me a set of numbers and says "draw the corresponding complete binary tree".
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.
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.
So build the binary tree with that in mind.
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?
Have a look at this article: Binary heap - Wikipedia, the free encyclopedia
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks