# Need help with binary trees and binary search trees.



## Daskill (Oct 17, 2007)

I've got to do some stuff with binary trees and binary search trees, but I'm having difficulty with it and was wondering if there might be some people here who could offer me help.

1) What's the difference between a binary tree and a binary search tree?

2) If I have a set of integers, say x = [5, 7, 12, 2, 4, 18, 9, 10, 1] and I have to put these into a binary tree, how do I decide where each integer goes, ie how do I decide what is the root, what are its children etc.

3) Same as above for a binary search tree. Are there any differences?

Thanks.


----------



## Mr Red (Dec 1, 2008)

if you use DEC2HEX() or DEC2BIN() in an adjacent column and then look for LEN() of result it should give clues - or at least help you do some text manipulation.

Not sure what is meant by root unless it is the MSB that is "1"


----------



## Daskill (Oct 17, 2007)

I didn't understand any of that. 

I've got to do this by hand, and I don't know what the rules are for putting a set of integers into a binary tree.

And, by root, I mean the root of the tree.


----------



## Mr Red (Dec 1, 2008)

I assumed you were using a spreadsheet. May not be a bad idea. 


Still don't follow your root. Is the root of numbers 2 & 3 - 0/1 ie the LSB of a binary number - or does it have a specific meaning in the context of your problem.


----------



## Daskill (Oct 17, 2007)

I don't know what you mean. I've just got a set of numbers for which I have to draw a binary tree. What I don't know is what order I'm supposed to put them into the tree.


----------



## Mr Red (Dec 1, 2008)

http://en.wikipedia.org/wiki/Binary_tree should move you on, not quite what I imgined. But read down to 
*Methods for storing binary trees*

and look at the picture


----------



## Daskill (Oct 17, 2007)

I think that's for storing a binary tree in an array. I want to know how to arrange a set of integers into a binary tree.


----------



## Mr Red (Dec 1, 2008)

I would think if you are writing it on paper start with a grid (or notional geographic grid) and place the numbers as if it was an array.

The branches then would run through numbers that are not present even though their position is implied. Missing numbers would just have the line through to the next level/branch.

You can then economise the whitespace as a second iteration.

The link shows your tree at the top right hand area.


----------

