A Binary Search Tree (BST) is a binary tree such that for each node, say N, the following statements are true:

* If L is any node in the left subtree of N, then **L **is ** less** than N.

* If R is any node in the right subtree of N, then **R** is ** greater** than N.

**Example:**

** Elements:** the elements are nodes (BSTNode), each node contains the following data type: Type,Key and has LeftChild and RightChild references. .

** Structure:** hierarchical structure; each node can have two children: left or right child; there is a root node and a current node. If N is any node in the tree, nodes in the left subtree < N and nodes in the right subtree > N.

** Domain:** the number of nodes in a BST is bounded; type/class name is BST

__Operations__

__Operations__

**Method** FindKey (int tkey, boolean found).
**requires: **none.
**input:** tkey.

**results:** If bst contains a node whose key value is tkey, then that node is made the current node and found is set to true; otherwise found is set to false and either the tree is empty or the current node is the node to which the node with key = tkey would be attached as a child if it were added to the BST.
**output:** found.

find (50)

find (30)

**Method** Insert (int k, Type e, boolean inserted)

**requires**: Full (bst) is false. **input**: key, e.

**results**: if bst does not contain k then inserted is set to true and node with k and e is inserted and made the current element; otherwise inserted is set to false and current value does not change.

**output**: inserted.

**Method** Remove_Key (int tkey, boolean removed) **input**: tkey

**results:** Node with key value tkey is removed from the bst and removed set to true. If BST is not empty then root is made the current.

**output**: removed

**Method **Update(int key, Type e, boolean updated)

**requires:** Empty(bst) is false. **input:** key, e. **results:** current node’s element is replaced with **Output:** updated.

Other methods that are same specification:

**Method** Traverse (Order ord)

**Method** DeleteSub ( )

**Method** Retrieve (Type e)

**Method** Empty ( boolean empty ).

**Method** Full (boolean full)

### Element

### Implementation

### Searching

The search operation in a binary search tree can be carried out as:

__While__ (the target element is not found __and__ there is more tree to search) __do__

__if__ the target element is “less than” the current element __then__ search the left

subtree __else__ search the right subtree.

### Insert

### Deletion

There are three cases:

Case 1: Node to be deleted has no children.

Case 2: Node to be deleted has one child.

Case 3: Node to be deleted has two children.

In all these case it is always a leaf node that gets deleted

Delete 80

After deleting

Delete 40

After deleting

### Delete Case: 2

Node to be deleted has one child.

Remove the node, and place its child (along with its subtree) in its place.

The parent will be linked with the child of the deleted node.

Delete 110

After Deleting

Delete 30

After Deleting

### Delete Case: 3

Node to be deleted has two children.

Complex case:

* Find the node with the minimum key in the right subtree (left-most node in

the right subtree).

* Copy its key/data over the node to be deleted.

* Delete the duplicate node (using either Case 1 or 2)

The node will be overwritten by the minimum node in the right subtree. Then that duplicate node will be deleted.

Delete 60

First find min in right sub tree and then delete, here 70 is min in right subtree which take the position of 60.

After Deleting

If you need any programming assignment help in Java Data Structure , Java Data Structure project or Java Data Structure homework then contact us at:

Send your request at realcode4you@gmail.com and get instant help with an affordable price.

We are always focus to delivered unique or without plagiarism code which is written by our highly educated professional which provide well structured code within your given time frame.

If you are looking other programming language help like C, C++, Java, Python, PHP, Asp.Net, NodeJs, ReactJs, etc. with the different types of databases like MySQL, MongoDB, SQL Server, Oracle, etc. then also contact us.

## コメント