Java:
Create a BST with input keys S E X R A C. (Assume the values are 1,2,3,4,5,6, resp.)
========================
JAVA PROGRAM
========================
///////////////BST.java/////////////////
//Class: BST
public class BST {
/**
*inner class Node
*/
class Node {
String key;
int value;
Node left;
Node right;
//constructor
public Node(String key,int value){
this.key = key;
this.value = value;
}
@Override
public String toString() {
return "Node [key=" + key + ", value=" + value + "]";
}
}
private Node root;
/**
* public method insert
* It will call insertKey method
* by passing root node along with key and value
* @param key
* @param value
*/
public void insert(String key,int value){
root = insertKey(root,key,value);
}
/**
* private recursive method insertKey
* It will insert the node at its proper position
* in binary search tree
* @param node
* @param key
* @param value
* @return
*/
private Node insertKey(Node node, String key,int value){
if(node == null){//if node is null
return new Node(key,value);//return a new Node
}
//compare current key , with key of current node
int compareValue = key.compareTo(node.key);
if(compareValue < 0)//if it is lesser
node.left = insertKey(node.left,key,value);//insert key in left child
else if(compareValue > 0)//if it is greater
node.right = insertKey(node.right,key,value);//insert key at right child
else //if it is same
node.value = value;//update the value
return node;
}
/**
* public method printTree
* It will call private method print
* by passing root Node
*/
public void printTree(){
System.out.println("Traversing Binary search Tree In-order:");
print(root);
}
/**
* print tree with in-order traversal
* this is a recursive method
* @param node
*/
private void print(Node node){
if(node ==null)
return;
//print inOrder
print(node.left);//left child
System.out.println(node);//print node
print(node.right);//right child
}
}
/////////////////////TestBST.java//////////////////////
//Test class: TestBST
public class TestBST{
//main method
public static void main(String[] args){
BST bst = new BST();//create a new instance of BST
//insert keys as given with their values
bst.insert("S", 1);
bst.insert("E", 2);
bst.insert("X", 3);
bst.insert("R", 4);
bst.insert("A", 5);
bst.insert("C", 6);
//finally print the Binary search tree with
//inserted nodes in-order
bst.printTree();
}
}
================================
OUTPUT
================================
Traversing Binary search Tree In-order:
Node [key=A, value=5]
Node [key=C, value=6]
Node [key=E, value=2]
Node [key=R, value=4]
Node [key=S, value=1]
Node [key=X, value=3]
Java: Create a BST with input keys S E X R A C. (Assume the values...
1a) Draw the 2-3 tree that results when you insert the keys S E A R C H X M P L Y in that order into an initially empty tree. 1b) Construct the corresponding left leaning red-black tree from part a. 1c) Find a sequence of keys to insert into a BST and a left leaning red-black BST such that the height of the BST is less than the height of the left leaning red-black BST, or prove that...
JAVA CODE Write a JAVA program to do the following. Input an integer x. (Should work with “big” numbers.) Create a completely-skewed BST S containing 1, 2, . . . , x. Create a BST R containing x integers without repetitions gen- erated at random. (To minimize the risk of repetitions, you can multiply the value returned by random() by a big number.) Given that the numbers are generated uniformly at random, the tree will likely be balanced. Measure the...
describe or draw the BST that results when you insert the keys E A S Y Q in that order using root insertion
C programming Create a BST with following values :{5.5,9.88,3.15,4.7,10.5} find the two maximum values in the tree Find the two minimum values in the tree
Write an efficient java program to implement BST. Your java program should read n words and its corresponding French and store it in a BST. Then read every English word and print its corresponding French by searching in BST. Assume your java program is in engtofren.java file To compile: javac engtofren.java To execute: java engtofren< any data file name Your main method should be as follow: public static void main(String args[]) { engtofren bst = new engtofren (); // try{...
Could you guys write an efficient java program to implement BST. Your java program should read words and its corresponding French and store it in a BST. Then read every English word and print its corresponding French by searching in BST. Assume your java program is in xxxxx5.java file (5th java project), where xxxxx is the first 5 characters of your last name. To compile: javac xxxxx5.java To execute: java xxxxx5 < any data file name Your main method should...
Q8 BST 15 Points Given a BST T with root r write algorithms (pseudocode) to determine: (a) The height of T. (b) The maximum element in T. (c) If T is height balanced. Please select file(s) Select file(s) Q9 Double 15 Points Consider inserting the keys 10, 22, 31, 4, 15, 28, 17, 88,59 into a hash tabl- (1) lend
Assume that R(A, B, C, D, E, F) has been decomposed into S(A, C, E, F) and other relations. If the dependencies for R are: AB rightarrow C, C rightarrow E, E rightarrow D, D rightarrow F, F rightarrow D. (a) Find ALL non-trivial functional dependencies that hold in S (b) Determine the keys and superkeys of S (c) For each one of your functional dependencies from part a) indicate if it is a BCNF violation, a 3NF violation or...
package hw3; import java.util.LinkedList; /* *********************************************************************** * A simple BST with int keys and no values * * Complete each function below. * Write each function as a separate recursive definition (do not use more than one helper per function). * Depth of root==0. * Height of leaf==0. * Size of empty tree==0. * Height of empty tree=-1. * * TODO: complete the functions in this file. * DO NOT change the Node class. * DO NOT change the name...
1. Recall that x E R is positive (resp. negative) if x = (an) which is positively (resp textitnegatively) bounded away from 0. Prove the following LIM00 an for a Cauchy sequence n-oo (a) For any E R, exactly one of the following is true: x is positive, is negative, or x= 0 E R is positive if and only if -x is negative. (b) (c) If x, y E R are both positive, then x + y and xy...