Question: Write a java program to implement the following algorithms for Binary Search Tree. ( Assume the tree only contains integer keys ) . TREE -

Write a java program to implement the following algorithms for Binary Search Tree. (Assume the tree
only contains integer keys).
TREE-INSERT (T,z)
y= NIL
x= T.root
while x NIL
y=x
if z. key x=xx=xz*p=yy===z,??T,(x,k)z,1x==k==x=z,3(x.left,k)(x.right,k)(x)(x)xx=xxxx=xx(T,x)xx(x,k)k. key
return TREE-SEARCH (x.left,k)
else return TREE-SEARCH (x.right,k)
TREE-Minimum (x)
TREE-MAXImum (x)
while x.right NIL
x=x. right
return x
while x.left NIL
x=x. left
return x
Write the following methods in java and test them in the main () method.
BSTInsert (T,x)
TreeMinimum (x)
TreeMaximum (x)
TreeSearch (x,k). key ,1ifx== NIL ork==x. key
else y. right =z,3ifk. key
return TREE-SEARCH (x.left,k)
else return TREE-SEARCH (x.right,k)
TREE-Minimum (x)
TREE-MAXImum (x)
while x.right NIL
x=x. right
return x
while x.left NIL
x=x. left
return x
Write the following methods in java and test them in the main () method.
BSTInsert (T,x)
TreeMinimum (x)
TreeMaximum (x)
TreeSearch (x,k)
x=x.left
else x=x.right
z*p=y
ify== NIL
T. root =z,?? tree T, TREe-SEARCH (x,k)
elseif z. key . key ,1ifx== NIL ork==x. key
else y. right =z,3ifk. key
return TREE-SEARCH (x.left,k)
else return TREE-SEARCH (x.right,k)
TREE-Minimum (x)
TREE-MAXImum (x)
while x.right NIL
x=x. right
return x
while x.left NIL
x=x. left
return x
Write the following methods in java and test them in the main () method.
BSTInsert (T,x)
TreeMinimum (x)
TreeMaximum (x)
TreeSearch (x,k)
 Write a java program to implement the following algorithms for Binary

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

To implement the specified algorithms for a Binary Search Tree BST in Java follow these steps Step 1 Define the Node Class java class Node int key Nod... View full answer

blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!