Reputation: 6931
I have a given integers set like ( 18, 22,7,23,25,37 ) . I have knowledge about Binary search tree. but for this case i can't understand what will be the root node & where to start ?
Upvotes: 0
Views: 114
Reputation: 1271
Well to begin with you can just have the first element as your root and then add any element that is less than root to its left and greater than it to its right and so on.
18
7 22
23
25
37
This makes sense when the numbers that are inserted are in random order, else in case or sorted numbers it will be as bad as a linked list. In fact in your example, half the numbers are in sorted order already.
Upvotes: 1