From the command line, accept the following as input, in this order:

  • The name of the input file (referred to as input.txt below)
  • The name of the output file (referred to as output.txt below)
  • The number of threads to be used: referred to as NUM_THREADS below
  • The words that need to be deleted in a single argument. So, the delete words will be provided in the following way: "XYZ1 XYZ2 XYZ3".
  • Debug Value: an integer that controls what is printed on stdout
    • Validate that the correct number of command line argumets have been passed.
    • Validate that the value of NUM_THREADS is an integer between 1 and 3.
    • Validate that he number of delete words is equal to NUM_THREADS
    • Validate that the DEBUG_VALUE is an integer between 0 and 4.
  • The input.txt file will have words that are delimited by whitespace or newline.
  • Here is an example of input.txt file:
A quick brown fox jumps over the lazy dog
The question of whether a computer can think is no more interesting than the question of whether a submarine can swim Edsger W Dijkstra

The best programs are written so that computing machines can perform
them quickly and so that human beings can understand them clearly A
programmer is ideally an essayist who works with traditional aesthetic
and literary forms as well as mathematical concepts to communicate
the way that an algorithm works and to convince a reader that the
results will be correct Donald Ervin Knuth Selected Papers on Computer
Science
  • Here is a sample output file (does not correspond to the input file above:
The total number of words: 50
The total number of characters: 200
The total number of distinct words: 30
  • It is possible for the delete words to be repeated. For example, "XYZ1", "XYZ2", "XYZ1".
  • The input file should be parsed and stored in a tree. Each distinct word should be stored in a distinct node. Choose the tree (BST, AVL, etc.) to optimize the operations to determine the total number of words, total number of characters, and total number of distinct words. Justify your choice of tree in the README.txt file in terms of time complexity for each of the three operations, and for the best, worst, and average case. You cannot use any data structure outside the tree to make these determinations. It is acceptable to have a data structure inside the Node.
  • Start all the populate threads (total NUM_THREADS) to populate the tree. Your code should ensure that a word is ready only once.
  • Next, start the delete threads (total NUM_THREADS) to search for the occurrences of the delete word in the tree. A thread should only reduce the occurrence of the delete word by 1. So, there are 5 occurences in the tree, a thread should reduce it to 4. However, if another thread also has the same delete word, then there should be 3 occurrences remaining in the end. If the number of occurrences is 0, then a thread should skip updating that word. If a Node ends up with 0 words, then the node should NOT be deleted. As the NUM_THREADS and number of delete threads are equal, assign a deleted word to each search thread.
  • The total number of words, characters, and distinct words should be determined after the populate and delete operations have completed.
  • The Driver code should create an instance of CreateWorkers and pass an instance of the FileProcessor, Results, other instances needed by the Worker to the constructor of CreateWorkers. The Driver should invoke the method startPopulateWorkers(...) in CreateWorkers and pass the NUM_THREADS as an argument.
  • The Driver should invoke a method on a reference (you decide which method and reference are appropriate) to determine the total number of words, characters, and distinct words.
  • The Driver should invoke the method startDeleteWorkers(...) in CreateWorkers.
  • You can pass arguments, as necessary, to the methods in CreateWorkers.
  • CreateWorkers' startPopulateWorkers(...) method should create NUM_THREADS threads (via the threaded class PopulateThread), start them and join on them. The instances fo FileProcessor, Results, and classes needed for the scheduling should be passed to he constructor of the worker thread class.
  • CreateWorkers' startDeleteWorkers(...) method should create NUM_THREADS threads (via the threaded class DeleteThread), start them and join on them. The instances fo FileProcessor, Results, and classes needed for the scheduling should be passed to he constructor of the worker thread class.
  • The run method of the worker threads should do the following till the end of file is reached:
    • While the end of file has not been reached:
    • Invoke a method in the FileProcessor to read one line as a string
    • Run your algorithm to insert/search/delete
  • The choice of data structure used in the Results class should also be justified in the README.txt in terms of time complexity (average, best, worst case).
  • The Results class should implement an interface, StdoutDisplayInterface. This interface should have a method writeToScreen(...). The driver should invoke this method on the Results instance whenever the appropriate debug level is enabled (for your own debugging purpose).
  • The Results class should implement an interface, FileDisplayInterface. This interface should have a method writeSchedulesToFile(...). The driver should invoke this method on the Results instance to print to output.txt, irrespective of the debug level.
  • Assume that the input file will not have any punctuations or special characters. It is possible for words to be separated by multiple white spaces and empty lines. It is possible for the input file to be empty.
  • Except in the MyLogger, do not make any other method static.
  • The DEBUG_VALUE, read from the command line, should be set in the MyLogger class. Use the DEBUG_VALUE in the following way:
    • DEBUG_VALUE=4 [Print to stdout everytime a constructor is called]
    • DEBUG_VALUE=3 [Print to stdout everytime a thread's run() method is called]
    • DEBUG_VALUE=2 [YOU DECIDE and explain in README.txt]
    • DEBUG_VALUE=1 [YOU DECIDE and explain in README.txt]
    • DEBUG_VALUE=0 [No output should be printed from the application to stdout. However, it doesn't affect what's get written to the output file.]
Academic Honesty!
It is not our intention to break the school's academic policy. Posted solutions are meant to be used as a reference and should not be submitted as is. We are not held liable for any misuse of the solutions. Please see the frequently asked questions page for further questions and inquiries.
Kindly complete the form. Please provide a valid email address and we will get back to you within 24 hours. Payment is through PayPal, Buy me a Coffee or Cryptocurrency. We are a nonprofit organization however we need funds to keep this organization operating and to be able to complete our research and development projects.