How do you insert a new item in a binary search tree?



How do you insert a new item in a binary search tree?..

Answer / Santosh Shaw

To insert a new item into a binary search tree, follow these steps:
1. Perform an initial search to find the appropriate location for the new node.
2. If the searched location is null (empty), create a new node with the input value and assign it to that location.
3. If the searched location already contains a value, compare the input value with the current value. If the input value is less than the current value, repeat the search process on the left subtree. Otherwise, repeat the search process on the right subtree.

Is This Answer Correct ?    0 Yes 0 No

Post New Answer

More Data Structures Interview Questions

What are the complexity of binary search?

1 Answers  


Explain the principle of quicksort. What is its complexity?

1 Answers   HAL,


If we add enum constants to a sorted collection ( treemap , treeset ), what will be the order in which they will be maintained?

1 Answers  


Is int a data structure?

1 Answers  


What is Doubly link list?

1 Answers   TCS,


Explain about set and their types in a collection?

1 Answers  


Does arraylist have index?

1 Answers  


What is meant by linked list?

1 Answers  


Given an unsorted linked list, and without using a temporary buffer, write a method that will delete any duplicates from the linked list?

1 Answers  


Advanced problems related to Data Structures were asked

1 Answers   Motorola,


What are hash tables good for?

1 Answers  


Which process places data at the back of the queue?

1 Answers  


Categories