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.
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
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.
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.
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.
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)
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.
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 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 Case: 3
Node to be deleted has two children.
* 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.
First find min in right sub tree and then delete, here 70 is min in right subtree which take the position of 60.
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 firstname.lastname@example.org 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.