Learn basic concept of c , c++ and python programming in regularcodes.com

Spread the post

Insertion of binary search tree(BST)

Binary search tree (BST) it follow following property.

1) root node are top of the tree. There are first inserted node of tree.

2) if inserting newly node of tree and its value are lesser of root node. Then it will put on left side of root node. Its called left subtree.

3) if inserting new node of tree and that value is greater of root node. Then it will put on right side of root node.

suppose following data [504, 485, 528, 450, 527, 576, 428, 574, 438, 535] are inserting on tree. inserting first node [504] of bst.

504

Try it yourself

Insertion another node [485].

504485

Try it yourself

Insertion another node [528].

504485528

Try it yourself

Insertion another node [450].

504485528450

Try it yourself

Insertion another node [527].

504485528450527

Try it yourself

Insertion another node [576].

504485528450527576

Try it yourself

Insertion another node [428].

504485528450527576428

Try it yourself

Insertion another node [574].

504485528450527576428574

Try it yourself

Insertion another node [438].

504485528450527576428574438

Try it yourself

Insertion another node [535].

504485528450527576428574438535

Try it yourself

Algorithm:

Time complexity of this program O(n)

Code execution:

BST insertion process

In this execution process not imagination all steps. below link click and view how to insert bst node, how to show all bst node.

C program to insert binary search tree element. Iterative approach.

Output
  Inorder BST data :  428  438  450  485  504  527  528  535  576  578 

Spread the post

Recommended Posts: