Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Using the included file BasicSTTester.java as a starting point, you will be making a NEW Class called BinarySearchTester.java . Use command line arguments to input

Using the included file BasicSTTester.java as a starting point, you will be making a NEW Class called BinarySearchTester.java.

Use command line arguments to input the file data into the program. DO NOT HARD CODE THIS VALUE INTO THE PROGRAM! USE ARGS!

Run all tests with the attached vowelsST.txt file.

In addition to the first section "Building a simple BinarySearchST" which uses looped put() and get() methods, you'll be adding sections for the following methods and tests:

Test the size() method to show how big the starting ST is.

Test an individual put() method with a consonant letter (i.e. "C" or "S") that is NOT in the vowelsST.txt file and show it's new place in the ST.

Test the size() method again to show the ST has grown.

Test another individual put() method that puts that SAME consonant letter (from above) into the ST again and show the results in the ST.

Test the delete() method to remove that new consonant, and show results

Test the rank() method to show the place of the new consonant in the ST

Test the ceiling() and floor() methods on a DIFFERENT consonant letter (i.e. "N" or "V") to see where it would go in the ST if it were put there

Test the min() method to show the min value in the ST

Test the max() method to show the max value in the ST

Test the deleteMin() method and show the results

Test the deleteMax() method and show the results

Your output should be formatted like the attached BSTester.txt output file. Not all tests are shown in this file, so be creative with your output.

Copy and paste the output from your terminal window into a BinarySearchTesterOUTPUT.txt.

Sample execution:

java-algs4 BinarySearchTester < vowelsST.txt
Building a simple BinarySearchST
Getting all items from file
---------------------
keys = A E I O U
vals = 0 1 2 3 4
size = 5
 
Putting C into BinarySearchST...
---------------------
keys = A C E I O U
vals = 0 5 1 2 3 4
size = 6
 
...
 
Testing deleteMax() (U) from BinarySearchST...
---------------------
keys = E I N O
vals = 1 2 5 3
size = 4

Create a new Java Class named RandomStrings that generates a list of random "words":

Takes three arguments: minimum word length (int), maximum word length (int), number of words to generate (int)

Words must be randomly sized from minimum word length to maximum word length

Letters in the words must be randomly generated. Use the String.valueOf((char) StdRandom.uniform(65, 91)) statement from the mid-term to generate the random letters.

Use a similar random statement to determine the random length of the word, but be careful because you can't randomize a length where min and max are equal... StdRandom.uniform(1, 1) won't work!

Sample execution:

java-algs4 RandomStrings 1 4 6

B

RAS

OG

Y

IEUY

KL

Should be able to pipe/redirect output to either a Java program or a text file.

Run your BinarySearchTester app with data generated DIRECTLY (not a file) from RandomStrings 1 1 8 and save output as RandStr2BSTOutput.txtSample Execution:

java-algs4 RandomStrings 1 1 8 | java-algs4 BinarySearchTester

Building a simple BinarySearchST

Getting all items from file

---------------------

keys = E F G N Q R V

vals = 0 7 5 4 2 3 6

size = 7

BasicSTTester.java

import edu.princeton.cs.algs4.BinarySearchST; import edu.princeton.cs.algs4.StdIn; import edu.princeton.cs.algs4.StdOut; public class BasicSTTester { public static void main(String[] args) { // DO NOT HARDCODE A FILENAME HERE. USE ARGS! // Test 01 - Building the BinarySearchST StdOut.println(); StdOut.println("Building a simple BinarySearchST"); StdOut.println("Getting all items from file"); StdOut.println("---------------------"); BinarySearchST test01 = new BinarySearchST(); for (int i = 0; !StdIn.isEmpty(); i++) { String key = StdIn.readString(); test01.put(key, i); } StdOut.print("keys = "); for (String s : test01.keys()) StdOut.print(s + " "); StdOut.println(); StdOut.print("vals = "); for (String s : test01.keys()) StdOut.print(test01.get(s) + " "); StdOut.println(); // Test 02 - Testing size() // Test 03 - Testing put() for individual item // Test 04 - Testing size() again // etc... } }

BSTester.java

Building a simple BinarySearchST Getting all items from file --------------------- keys = A E I O U vals = 0 1 2 3 4 size = 5 Putting C into BinarySearchST... --------------------- keys = A C E I O U vals = 0 5 1 2 3 4 size = 6 Putting C (again) into BinarySearchST... --------------------- keys = A C E I O U vals = 0 6 1 2 3 4 size = 6 The ^ shows C's rank (1) from BinarySearchST... --------------------- keys = A C E I O U vals = 0 6 1 2 3 4 index = 0 ^ 2 3 4 5 Deleting C from BinarySearchST... --------------------- keys = A E I O U vals = 0 1 2 3 4 size = 5 Testing floor() and ceiling() for N in BinarySearchST... --------------------- keys = A E I O U vals = 0 1 2 3 4 c/f = \ / Putting N into BinarySearchST... --------------------- keys = A E I N O U vals = 0 1 2 5 3 4 size = 6 The ^ shows the min() (A) from BinarySearchST... --------------------- keys = A E I N O U vals = 0 1 2 5 3 4 min = ^ Testing deleteMin() (A) from BinarySearchST... --------------------- keys = E I N O U vals = 1 2 5 3 4 size = 5 The ^ shows the max() (U) from BinarySearchST... --------------------- keys = E I N O U vals = 1 2 5 3 4 max = ^ Testing deleteMax() (U) from BinarySearchST... --------------------- keys = E I N O vals = 1 2 5 3 size = 4 

vowelsST.txt

A E I O U

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Machine Learning And Knowledge Discovery In Databases European Conference Ecml Pkdd 2010 Barcelona Spain September 2010 Proceedings Part 3 Lnai 6323

Authors: Jose L. Balcazar ,Francesco Bonchi ,Aristides Gionis ,Michele Sebag

2010th Edition

3642159389, 978-3642159381

More Books

Students also viewed these Databases questions

Question

8. Explain the difference between translation and interpretation.

Answered: 1 week ago

Question

10. Discuss the complexities of language policies.

Answered: 1 week ago

Question

1. Understand how verbal and nonverbal communication differ.

Answered: 1 week ago