Question: pseudocode for this problem that I need to solve and didnt yet: List - Search(L,k) x = L.head while x is not equal to nil
pseudocode for this problem that I need to solve and didnt yet:
List - Search(L,k)
x = L.head
while x is not equal to nil and x.key is not equal to k
x=x.next
return x
Tree= Successor(x)
if x.right is not equal to NIL
return Tree- Minumum(x.right)
y = x.p
while y is not equal to NIL and x == y.right
x = y
y = y.p
return y
Tree_insert(T,z)
y = Nil
x = T.root
while x is not equal to NIL
y = x
if z.key
x = x.left
else x = x.right
z.p = y
if y == NIL
T.Root = z
elseif z.key
y.left = z
else y.right = z
THIS IS FOR JAVA!
Instructions. You are provided four skeleton program named TreeNode.java and BinarySearchTree.java. . Please modify the skeleton code to solve the following tasks. 1 . Implement the inorder tree walk() function.
2. Implement the search() function
3. Implement the iterative search() function
4. Implement the minimum() function
Task 5. Implement the maximum() function
Task 6 (20 pts). Implement the successor() function
Task 7 (20 pts). Implement the insert() function
Please, do not change the code given. Just apply what is asked.
package ds;
public class BinarySearchTree {
public TreeNode root;
public BinarySearchTree () {
root = null;
}
public void inorder_tree_walk (TreeNode x) {
}
public TreeNode search (TreeNode x, int k) {
}
public TreeNode iterative_search (int k) {
}
public TreeNode minimum () {
}
public TreeNode maximum () {
}
public TreeNode successor (TreeNode x) {
}
public void insert (int k) {
}
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
int[] array = {15, 6, 18, 3, 7, 17, 20, 2, 4, 13, 9};
BinarySearchTree bst;
TreeNode n;
bst = new BinarySearchTree();
for (int i = 0; i < array.length; i++)
bst.insert(array[i]);
System.out.println("Inorder_tree_walk starts ------------
------");
bst.inorder_tree_walk(bst.root);
System.out.println("Inorder_tree_walk ends --------------
----");
System.out.print(" ");
System.out.println("Search starts ------------------");
n = bst.search(bst.root, 13);
System.out.println("found: " + n.key);
System.out.println("Search ends ------------------");
System.out.print(" ");
System.out.println("Iterative search starts -------------
-----");
n = bst.iterative_search(4);
System.out.println("found: " + n.key);
System.out.println("Iterative search ends ---------------
---");
System.out.print(" ");
System.out.println("Minimum starts ------------------");
n = bst.minimum();
System.out.println("Minimum key is " + n.key);
System.out.println("Minimum ends ------------------");
System.out.print(" ");
System.out.println("Maximum starts ------------------");
n = bst.maximum();
System.out.println("Maximum key is " + n.key);
System.out.println("Maximum ends ------------------");
System.out.print(" ");
System.out.println("Successor starts ------------------
");
n = bst.successor(bst.root.left.right.right);
System.out.println("Successor key is " + n.key);
System.out.println("Successor ends ------------------");
System.out.print(" ");
}
}
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
