-3
$\begingroup$

The data are in alphabets.

U, N, I, V, E, R, S, I, T, Y, O, F, P, O, K, H, A, R, A.

Perform pre, in and post order traversals.

I'm confused as how to construct it in the 1st place. Only sense i can apply is assigning numbers to alphabets as A=1, B=2, .... Z=26.

But I got stuck on how to select the root node and also arrange duplicate data.

I would be grateful if you guys construct it for me.

$\endgroup$
  • 1
    $\begingroup$ There's no need to shout. This is a very basic question that should be covered by literally any reference that discusses binary search trees. We expect you to do some basic research before asking here. What references did you look at and what specifically were you unable to understand in them? $\endgroup$ – David Richerby Jun 29 '16 at 16:28
0
$\begingroup$

First of all you have to decide on how you want to compare your data, so assigning numbers to the letters was already a good start.

Next, your root node will be the first letter you put into your tree. E.g. 'U' in your case. Afterwards for insertion, you compare your letter with the node you are at and move left or right (depending on if it's smaller or bigger). Once you reach a "dead end", your letter will be inserted in that spot.

Regarding duplicate entries, it depends. You can add duplicate values to the corresponding node, or you could also use relations such as <=, > instead of <,>. (Put duplicate values to the left of a node, in that case.)

A really nice visualization of a binary search tree can be found here: https://www.cs.usfca.edu/~galles/visualization/BST.html

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.