Binary Search Trees (contd.)
•	Insert(t,x)
•	if t is null 
•	allocate space for t
•	t->data = x
•	else if t->data == x return;
•	else if t->data > x Insert(t->LeftChild,x)
•	else if t->data < x Insert(t->RightChild,x)
•	Search(t,x)
•	if t is null return false;
•	else if t->data == x 
•	x = t->data
•	return true;
•	else if t->data > x Search(t->LeftChild,x)
•	else if t->data < x Search(t->RightChild,x)
•	Delete
	template <class T>
	void BSTree<T>::Delete(BinaryTreeNode<T> *& t, T& x)
	{
	        if(t)
	        {
	                if(t->data == x)
	                {
	                        x = t->data;
	                        if(t->LeftChild && t->RightChild)
	                                PruneSuccessor(t);
	                        else
	                                Prune(t);
	                }
	                else if(t->data > x) Delete(t->LeftChild,x);
	                else if(t->data < x) Delete(t->RightChild,x);
	        }
	        else return;
	}
	template <class T>
	void BSTree<T>::Prune(BinaryTreeNode<T> *& t)
	{
	        BinaryTreeNode<T>* temp = t;
	        if(t->LeftChild)
	        {
	                t = t->LeftChild;
	        }
	        else // LeftChild must be NULL
	        {
	                t = t->RightChild;
	        }
	        delete temp;
	}
	template <class T>
	void BSTree<T>::PruneSuccessor(BinaryTreeNode<T> *t)
	{
	        BinaryTreeNode<T>* temp = t;
	        BinaryTreeNode<T>* parent = t;
	        temp = temp->RightChild;
	        while(temp->LeftChild)
	        {
	                parent = temp;
	                temp = temp->LeftChild;
	        }
	        t->data = temp->data;
	        if(parent == t)
	                Prune(parent->RightChild);
	        else
	                Prune(parent->LeftChild);
	}
•	Insert the following numbers in a BST
•	7,14,21,28,35,42,63,70,77,84
•	The above is the worst case, where BST is a chain
•	Height of a BST will be between log n and n
•	The worst case search requirement for a BST is O(n).
•	We can use a special case of BSTs called AVL trees which gurantee O(log n) search time.