# Insertion in a Binary Search Tree JAVA

20:31

__Insertion in a Binary Search Tree :___**Insertion in a BST follow simple operations. All the elements less than root lies on left subtree and all the elements greater than root lies on right subtree.**

Every BST class will have a root variable of Node type that represents the head node of the tree.

public class BinarySearchTree { Node root; public BinarySearchTree() { root=null; }

public Node insert(Node node,Node root) { if(root==null) { root=node; return root; } else{ if(node.data>root.data) { root.right=insert(node,root.right); } else if(node.data<root.data) { root.left=insert(node,root.left); } } return root; } }

## 0 comments