Single binary search tree

Assignment Help Data Structure & Algorithms
Reference no: EM13186033

In this assignment, you are to write a program that analyzes a selection of text, counting the number of times each word appears in the text. Your word counts must ignore capitalization, so the, The, THE, and tHe all increase the count for the word "the" by one. For purposes of this assignment, a word is any consecutive string of letters and the apostrophe character, so don't counts as a single word, and best-selling counts as two words: best and selling. Notice that a blank space will not necessarily occur between two words. Numbers such as 27 and 2/3 will NOT be counted as words.

You must store the words and the counts of the words in a single binary search tree. Each word occurring in the text can only be stored once in the tree. Call the structure for the nodes of the tree WordNode, and call the references in this structure left and right. Use Strings to store words in the tree. Call the class implementing the binary search tree WordTree. It must contain the following public methods:

- constructors
- add: adds the given word to the tree if it is not already in the tree OR increments the appropriate counter if it is already there. It returns nothing.
- countNodes: returns the number of words currently stored in the tree.
- countWordsWith4Chars: returns the number of words which have exactly four characters.
- print: display the words of the tree in alphabetical order, and next to each word, prints the number of times each word occurs in the text.

Three of these operations (all but add) must visit every node in the tree. One of these must use preorder traversal, one must use inorder traversal, and one must use postorder traversal. You must decide which to use for each method, but use comments to document the type of traversal used.

The WordTree class may have only one data member variable, root, and it must be private.

Your program should perform the following steps:

1. Prompt the user for the name of the file (a string). Use the string input by the user as an argument to open file:

2. Open the file on disk, and process its contents, adding unique words to the BST and increasing the counts of existing words if necessary

3. Repeat steps 1&2 until the user enters some sentinel value.

4. Print out the total number of nodes in your tree

5. Print out the number of words which have exactly four characters.

6. print out the contents of a tree in alphabetical order

Reference no: EM13186033

Questions Cloud

Article about forest health and wildlife habitat : An article about forest health and wildlife habitat. This article should either address a controversial issue or concern or present a unique approach to solving a relevant problem, 200-300 words.
What happens to the demand for loanable funds : Using the 3-graph model developed in chapter 14, consider first the impact on the demand for loanable funds. If businesses respond as expected to the investment-tax credit, what will happen to the demand for loanable funds Given this, what, if any..
Relationship with the customer : Why is Prius's success dependent on Toyota's relationship with the customer? Do you think Toyota has demonstrated their motto that "Customer is King/Queen" through development of the Prius? If so, how?
News-gathering gone too far : “You can’t have a free press without the press being free. This means uninhibited inquiry.” Vs “Decency should trump news-gathering that invades privacy, interferes with criminal investigations, and nothing to do with serving a public good.”
Single binary search tree : You must store the words and the counts of the words in a single binary search tree and each word occurring in the text can only be stored once in the tree
How will this policy affect national saving : Suppose Congress (in an attempt to stimulate the economy in both the short and long run) passes an investment-tax credit, which subsidizes domestic investment. How will this policy affect (comparing the state of the economy prior to the enactment o..
State what volume should dilute ki solution : what volume should you dilute 43.5mL of a 4.00M KI solution so that 24.0mL of the diluted solution contains
What type of market structure would farmers like to convert : The story states that good weather has resulted in an unexpectedly large crop, which we know will increase supply and reduce the market price for their coffee beans. If all of the farmers know that picking this large crop will guarantee them lowe..
State what is the perecent of nacl by mass in the sample : A smple of mixture of NaCl, Caco3 and SiO2 weighed 7.30 grams. During the water wash the sample lost 2.21 grams. After treatment with HCL, the sample weighed 2.05 grams.

Reviews

Write a Review

Data Structure & Algorithms Questions & Answers

  Find cost of sorting the relation in seconds

Suppose you need to sort a relation of 40 gigabytes, with 4 kilobyte blocks, using a memory size of 40 megabytes. Find the cost of sorting the relation, in seconds, with bb = 1 and with bb = 100.

  A local company owns three 3d printers

A local company owns three 3D printers installed in its three different branches. Clients can call the company and reserve the use of one printer for some hours.

  Design algorithm to produce list of customers

Design an algorithm to produce a list of customers from the Glad Rags Clothing Company's customer master file. Each record on the customer master file contains the customer's number.

  Sketch portion of decision tree via quicksort to sort array

Suppose you are using quicksort to sort array A with 6 distinct elements a1, a2, ..., a6. Sketch portion of the decision tree which corresponds to th ordering a3

  Question related to sequential files

In spite of the fact that sequential files lack direct targeted addressing of each of the records and fields, they are the most widely used.

  Using quicksort with median-of-three

Show the steps in details of sorting {3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5} using quicksort with median-of-three partitioning and a cutoff 3 (if the elements are less than 3, using insertion sort).

  Determine mean process turnaround time

Their priorities are 2, 3, 1, 5 and 4, respectively, with 1 being the highest priority. Specify the order in which processes execute and determine the mean process turnaround time for each of the scheduling algorithms.

  Singly linked list

Singly Linked List (SLL)Introduce a SLL class with the following functions. Please also introduce a main function that will invoke and verify whether the functions are implemented correctly

  Question about edge connectivity

The edge connectivity of an indirected graph is minimum number k of edges that must be removed to disconnect the graph.

  Describe an algorithm that takes as input a list

Describe an algorithm that takes as input a list of n distinct integers and finds the location of the largest even integer in the list or returns 0 if there are no even integers in the list.

  Write specifications using uml notation for a function

Write specifications using UML notation for a function that computes the sum of the first five positive integers in an array of  n  arbitrary integers.

  Developing a new customer order entry system

The system development team at Wilson Corporation is working on developing a new consumer order entry system. In the process on designing the new system,

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd