Implement a method to delete every node

Assignment Help Data Structure & Algorithms
Reference no: EM13315344

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

Optional: if you have time, implement a method to delete every node from your BST that contains a word that is 3 or fewer letters long (note that you must explicitly make these deletions, not fail to insert these words in the first place). 

Reference no: EM13315344

Questions Cloud

Cooling process is important in biotechnological application : To prevent chilling injury in the vegetables during the cooling process is very important in biotechnological applications. Potatoes (k=0.5 W/m oC and ?=0.13x10-6 m2/s) that are initially at a uniform temperature of 25 oC and have an average diameter..
Determine the components of the particles velocity : A 6.7uC particle moves through a region of space where an electrice field of magnitude 1300 N/C point in the positive x direction, find the components of the particle's velocity
Compose conceptual data modeling techniques : Prepare database design documents using the data definition, data manipulation, and data control language components of the SQL language.
Compute the magnitude of the acceleration of the crate : Two forces are applied to a 5.0 kg crate; one is 6.0 N to the north, compute The magnitude of the acceleration of the crate
Implement a method to delete every node : 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.
The health care organization-accreditation : Quality Improvement in the Health Care Organization-Accreditation
Agency power combines the executive and legislative powers : Agency power combines the executive and legislative powers with respect to rule making and the legislative and judicial powers with respect to adjudication. Pick two agencies and compare and contrast the power each agency has in enforcing the regulat..
Determine the weight w of the container to a ceiling : a container is supported by three cables that are attached to a ceiling. Determine the weight W of the container, knowing that the tension in cable AB is 6 kN
Calculate the potential at the point halfway between centers : Two metal spheres, each of radius 1.0 cm, have a center-to-center separation of 2.0 m. Sphere 1 has charge +2.90 10-8 C. Calculate the potential at the point halfway between the centers

Reviews

Write a Review

Data Structure & Algorithms Questions & Answers

  Implementation of graph

Give the two input nodes after the graph has been built from the command prompt.

  Design a control unit for simple hand held video game

Create a control unit for a simple hand held video game in which a character on the display catches objects. Only demonstrate the transition diagram

  Design analgorithm that decides for each node

Design an O(n) algorithm that decides (schedules) for each node at which time slot to start sending data such that the total number of time (slots) is minimized.

  Creating an object oriented data model

Create an object oriented data model, including all appropriate notations, to represent the given situation. In a particular region there are a number of gardens.

  Algorithm to concatenate string in single binary search tree

Create algorithm which concatenates T1 and T2 into single binary search tree. Worst case running time must be O(h).

  Create a pda with 2 stacks

Create a PDA with 2 stacks. The first stack is preloaded with data (example below), the data input consists of 1 & 0 as well. Your PDA should process the input data, adding the binary string to the values in the first stack and storing the result in ..

  Cuckoo hashing

Using Cuckoo hashing, hash the following keys using the (h1,h2) pairs shown. A: 2,0 B: 0,0 C: 4,1 D: 0,1 E: 2,3 Using Hopscotch hashing with a max hop of 4, hash the following keys. A: 6 B: 7 C: 9 D: 7 E: 6 F: 7 G: 8

  Create algorithm to read file of employee records

Create the algorithm which will read a file of employee records and produce the weekly report of gross earnings for those employees.

  Analyze algorithm to determine length of longest substring

Explain and analyze the algorithm to determine the length of longest substring that appears both forward and backward in an input string T[1 . n].

  Dscribes the table created from each entity and the column

You are a database consultant with Ace Software, Inc. and have been assigned to develop a database for the Mom and Pop Johnson video store in town.

  Perform page trace analysis by fifo page removal algorithm

Using the FIFO page removal algorithm, do a page trace analysis indicating page faults with asterisks (*). Then compute the failure and success ratios.

  Creating an automated checkout program

A local department store employee you to create an automated checkout program to expedite customers in a hurry. The checkout line can only allow 5-products for any one purchase.

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