Binary Search Tree Insertion
Learn about the binary search tree insertion algorithm!
We'll cover the following
Binary Search Tree Insertion Algorithm
Here is a description of the algorithm used to insert a new value into a BST:
-
Start from the root node.
-
Check if the value to be inserted is greater than the root/current node’s value
-
If yes, then repeat the steps above for the right-subtree. Otherwise, repeat the steps above for the left-subtree of the current node.
-
Repeat until you find a node that does not have a right/left child to move onto. Insert the given value there, and update the parent node accordingly.
See the animation given below:
Level up your interview prep. Join Educative to access 70+ hands-on prep courses.