How to Build a Binary Search Tree with Given Data?

6 replies · 3K views · last reply
Henry R
Messages
25
Reaction score
0
Draw a Binary Search Trees (BST) produced when data containing 30,40,50,60,10,20,55,15 is inserted one by one.

Thanks.
 
Henry R said:
Draw a Binary Search Trees (BST) produced when data containing 30,40,50,60,10,20,55,15 is inserted one by one.

Thanks.

Note that every node on the right subtree has to be larger than the current node and every node on the left subtree has to be smaller than the current node.
 
evinda said:
Note that every node on the right subtree has to be larger than the current node and every node on the left subtree has to be smaller than the current node.

This is ...View attachment 3676
 
Attachments
  • Binary tree diagram with root 10, left child 15 and right child 30; 15 has children ? and 20, 30 has children ? and 40, with arrows pointing from parents to children.
    Binary tree.PNG
    6.4 KB · Views: 162
Henry R said:

Since the data is inserted one by one, $30$ has to be the root.
$40$ is greater than $30$, so it has to be at the right subtree.
So, at the beginning it should be like that:

View attachment 3677Can you continue? (Thinking)
 
Attachments
  • Binary search tree diagram: node 30 at the top with a right child node 40 connected by a line down and to the right.
    m.png
    799 bytes · Views: 176
evinda said:
Since the data is inserted one by one, $30$ has to be the root.
$40$ is greater than $30$, so it has to be at the right subtree.
So, at the beginning it should be like that:

https://www.physicsforums.com/attachments/3677Can you continue? (Thinking)

sure.View attachment 3679
 
Attachments
  • Binary tree diagram with levels labelled 1 to 4 on the right: node 30 at level 1, nodes 20 and 40 at level 2, nodes 10, 15, 55 and 60 at level 3, and node 50 at level 4.
    b.PNG
    9.4 KB · Views: 149
Bacterius said:
How is 55 smaller than 40?

Yeah! Sorry for that.