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{
Scanner inf = new Scanner (System.in);
// Read input from KB/ File
// read no. of words
n = inf.nextInt();
for (i = 1; i <= n; i++){
// read English word
english = inf.next();
// read corresponding word
french = inf.next();
bst.insert(english, french);
}
while(inf.hasNext()){
// read next English word
english = inf.next();
search in BST and print its corresponding French if exist.
}// end while
inf.close();// close input file
}catch (Exception e) {prt("\nException " + e + "\n");}
}//
Read input from System.in. i.e. command prompt.
Sample data file can be as follow:
5 student etudiant book livre this cette is est a une this is a book
The algorithm to insert data into BST is:
The algorithm to search is:
The java code is as follows:
import java.util.Scanner;
public class engtofren
{
// Root of BST
private Node root;
// Constructor
engtofren() {
root = null;
}
// This method mainly calls insertRecord()
void insert(String word, String meaning) {
root = insertRecord(root, word, meaning);
}
// A recursive function to insert a new key in BST
Node insertRecord(Node root, String word, String meaning) {
// If the tree is empty, return a new node
if (root == null) {
root = new Node(word, meaning);
return root;
}
// Otherwise, recur down the tree */
if (word.compareToIgnoreCase(root.word) < 0)
root.left = insertRecord(root.left, word, meaning);
else if (word.compareToIgnoreCase(root.word) > 0)
root.right = insertRecord(root.right, word, meaning);
//return the (unchanged) node pointer
return root;
}
public Node search(Node root, String key)
{
// root is null or key is present at root
if (root==null ||
root.word.equalsIgnoreCase(key))
{
return root;
}
// val is greater than root's key
if (root.word.compareToIgnoreCase(key)>0)
return search(root.left, key);
// val is less than root's key
return search(root.right, key);
}
public static void main(String args[]) {
engtofren bst = new engtofren (); //
try{
Scanner inf = new Scanner
(System.in);
// Read input from KB/ File
// read no. of words
System.out.println("Enter no of
words");
int n = inf.nextInt();
System.out.println("Enter
words");
for (int i = 1; i <= n;
i++){
// read English word
String english = inf.next();
// read corresponding word
String french = inf.next();
bst.insert(english, french);
}
while(inf.hasNext()){
// read next English word
String english = inf.next();
Node searchedNode=bst.search(
bst.root, english);
System.out.println(searchedNode.word + " : " +
searchedNode.meaning);
// search in BST and print its corresponding French if
exist.
}
inf.close();// close input file
}catch (Exception e) {System.out.println("\nException " + e + "\n");}
}
}
class Node
{
String word;
String meaning;
Node left, right;
public Node(String word, String meaning) {
this.word= word;
this.meaning=meaning;
left = right = null;
}
}

Write an efficient java program to implement BST. Your java program should read n words and...
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...
Write a java program to convert and print an infix expression to postfix expression. You can use Java stack methods. (Must read input from System.in) Your main method should be as follow: public static void main(String args[]) { intopost p = new intopost (); String iexp, pexp; //infix postfix expression try{ Scanner inf = new Scanner (System.in); // Read input from KB/ File while(inf.hasNext()){ // read next infix expression iexp = inf.next(); // Assume method name to convert infix...
Write a French/English dictionary lookup program. Read a list of pairs of English and French words from a file specified by the user. English/French words should be exact matches (don't try to find partial matches). Use the supplied EnglishFrenchDictionary.java class as your main class. Fill in the missing code in the DictionaryTable.java class to read the input file and perform the searches. Add code to the DictionaryTable read() method to: read pairs of lines (English word is on the first...
In this assignment you will implement the second version of your spell checker. Using the randomized dictionary (random_dictionary.txt) given, read in the dictionary into an array of 26 Binary Search Trees (BST) , one for each letter of the alphabet. Thus the first BST would contain only those words starting with letter 'a', while the last would contain only those words starting with letter 'z'. Then, when you read in the book (oliver.txt), you examine the first character of each...
In this assignment you will implement the second version of your spell checker. Using the randomized dictionary (random_dictionary.txt) given, read in the dictionary into an array of 26 Binary Search Trees (BST) , one for each letter of the alphabet. Thus the first BST would contain only those words starting with letter 'a', while the last would contain only those words starting with letter 'z'. Then, when you read in the book (oliver.txt), you examine the first character of each...
Today you are to write a Java program that will prompt for and
read 2 words of equal length entered by the user, and create a new
word which contains the last letter of the 1st word, the last
letter of the 2nd word, followed by the second to last character of
the 1st word, followed by the second to last character of the 2nd
word and so on. Be sure to use the same format and wording as in...
Write a Python program to read lines of text from a file. For each word (i.e, a group of characters separated by one or more whitespace characters), keep track of how many times that word appears in the file. In the end, print out the top twenty counts and the corresponding words for each count. Print each value and the corresponding words, in alphabetical order, on one line. Print this in reverse sorted order by word count. You can assume...
I cant get this python program to read all the unique words in a file. It can only read the number of the unique words in a line. import re import string from collections import Counter # opens user inputted filename ".txt" and (w+) makes new and writes def main(): textname = input("Enter the file to search: ") fh = open(textname, 'r', encoding='utf-8' ) linecount = 0 wordcount = 0 count = {} print("Sumary of the", fh) for line in...
Write a program IN PYTHON that checks the spelling of all words in a file. It should read each word of a file and check whether it is contained in a word list. A word list available below, called words.txt. The program should print out all words that it cannot find in the word list. Requirements Your program should implement the follow functions: main() The main function should prompt the user for a path to the dictionary file and a...
read the code and comments, and fix the program by INSERTING the missing code in Java THank you please import java.util.Scanner; public class ExtractNames { // Extract (and print to standard output) the first and last names in "Last, First" (read from standard input). public static void main(String[] args) { // Set up a Scanner object for reading input from the user (keyboard). Scanner scan = new Scanner (System.in); // Read a full name from the user as "Last, First"....