Compute the frequency for every unique character

Assignment Help JAVA Programming
Reference no: EM131735958

Assignment

Description:

This assignment will have us build a special kind of tree, and we will be building it from the ground up, i.e., from the leaves to the root.

The very first thing we will do is to ask the User for some input text - you should validate that the User has not inputted empty text. We will be building a tree based on this input such that:

• Every unique character in the input text will be a leaf node (i.e., the number of leaves will be equal to the number of unique characters).

• Every node that is not the root and is not a leaf will be some text containing some of the characters, such that each character appears just once.

• The root node will be some text containing each of the unique characters in the input string such that each character appears once and only once.

• Additionally, not just will each node contain some text (even if it is just one character) - which can be thought of as the data of the node, but also each node will be associated with a numeric weight which is calculated per the procedure below.

1. Given the input text we will compute the frequency for every unique character (the frequency is the number of occurrences of that character in the text). Every unique character will be a leaf node and the weight of each node will be the frequency of that character.

2. From all the uncombined nodes (initially all of the nodes are uncombined) - we pick the two nodes with the lowest weights and combine them to form a new node. The data of this new node will be the text obtained from concatenating the text of the constituent nodes, and the weight of the new node will be the sum of the weights of the constituent nodes.

a. You can think of this new node as the parent of the two constituent nodes.
b. This new node is now uncombined and its two children have been combined.

3. We repeat step 2 (each time combining the two lowest weighted uncombined nodes) until there are no non-root nodes left to combine, i.e., we are left with just the root node. Then the tree is complete. At every step, the relevant output should be presented (described on page 2).

Some assumptions you can make:

• You can assume that the input text is not case sensitive - i.e., an ‘a' in the text is the same as ‘A', and thus assume that all text inputted will be lower cased.

• There will be no spaces in the text that is inputted - other typical characters (for example: underscore, arithmetic operators, numbers etc.) are all fair game.

• When combining nodes, in case 2 nodes have the same weight, you are free to break ties however you want.

Important notes:

• Since only two nodes are combined two form a parent node - looking at this from the perspective of a tree, every parent has two children and thus, this is a binary tree.

• Since at every step the weight of the parent node is given by the sum of the child nodes, the final weight of the root node should be the length of the input text.

• When combining nodes together the parent data is basically just a combination of the child nodes' data: for example, if node A has a data of ‘x' and it is being combined with node B which has a data of ‘y', then the parent node could have ‘xy' or ‘yx' as its data'. It does not matter which way you do the combination - both are in fact correct and have no bearing on what we are trying to accomplish - just be consistent on how you decide on the parent node's text to make grading easier.

• A sample scenario of how this problem would be solved on paper is attached to this assignment description. Please go through it carefully and let us know if you find discrepancies or if there is any confusion.

Expected Output:

1. After the input text has been provided (and has been validated), the first thing that should be presented to the User is a table (formatted as you like) that lists all the unique characters and their associated frequencies sorted in descending order of their weights.

2. Then the User should be prompted to continue to the next step: by asking for some input (the input really doesn't matter - we just want a pause so the User can evaluate the current state before moving on to the next step. For example, the program can print "Ready for the next step" and as soon as the User hits Enter, the next step proceeds.

3. After the User proceeds, the program should print ‘Combined node {X} (weight: {a}) with node {Y} (weight: {b}) to produce node {Z} (weight {c}). The table is printed again for all the uncombined nodes (as per step 1) and the User is again prompted on whether they are ready to proceed per Step 2. Substitute:

a. {X} with the data of the first node (say the left child) and {a} with the weight of this node.
b. {Y} with the data of the second node (say the right child) and {b} with the weight of this node.
c. Substitute {Z} with your choice of how to do the concatenation and {c} with the weight as a result of the combination.

4. The above proceeds until the very end when we have created our root node (and printed the final table), and then instead of asking the User to continue, the program indicates that we are done and gracefully exits.

There is no requirement on whether you should have each class in its own java file or just submit one Java file.

* Remember to comment your code well and follow the rubric provided.
** Exercise judgment when programming such that your code accounts for special cases (e.g. validation, exception handling).

Reference no: EM131735958

Questions Cloud

Most significant it developments and applications : What are the most significant IT developments and applications that you expect to happen in the next ten years.
How does a recall positively impact an organization : How does a recall negatively impact an organization from the consumer or customer viewpoint, the organization's employee and management viewpoint, the Brand?
Define legal requirements placed on the agency : Define Legal requirements placed on the agency
Design and implement a cpp class which represents a book : Design and implement a C++ class which represents a Book, and use this class in a main program which reads in information for multiple books from a data file.
Compute the frequency for every unique character : Given the input text we will compute the frequency for every unique character (the frequency is the number of occurrences of that character in the text).
Explain why it is better to design quality into processes : All of the following reasons explain why it is better to design quality into processes than to find problems through inspections EXCEPT:
Which goal was the most important at the time your article : Which goal was the most important at the time your article was written - how to gain maximum learning and points from your discussion engagement
What business-level strategies are these supermarkets : What business-level strategies are these supermarkets currently pursuing? What kind of supermarket would do best against the competition?
Inchoate crimes-crimes against persons : List one example of each of the following types of crime: inchoate crimes; crimes against persons; crimes against property.

Reviews

Write a Review

JAVA Programming Questions & Answers

  Write a declaration for three classes using the inheritance

Write a declaration for all three classes using the principles of inheritence. Make the Building class abstract

  Write a java program to simulate a calculator

Write a JAVA program to simulate a calculator. Your program should take two numbers and an operator (+,-,*,or/), from the user in the following format: number1 operator number2 (For example 5.6 + 7.2) and print the result.

  Write a program to calculate a tuition bill for a student

Java Assignment- You are to write a program to calculate a tuition bill for a student. First you will read the following data from separate dialog boxes Name of the Student.

  What is the efficiency of insertion sort

What is the efficiency of insertion sort - What is the base case for the recursive merge sort algorithm?

  A meanu driven program which maintain a list of car models

A meanu driven program which will maintain a list of a car models and their price

  Write a java loop

write a java loop ( of your choice ) that produces exactly the following output to the screen: 2-4-6-8-

  Write a java program to read sequences of integers

Write a Java program to read sequences of integers from a text file, build a binary search tree for each sequence by inserting numbers in the sequence one after another into the search tree, and plot a picture of the finished tree.

  Write a java program based on the pseudo code you designed

Write a Java program based on the pseudo code you designed. The program should have meaningful variable names CSE1PGX.

  Prepare a polynomial-time algorithm

Write a polynomial-time algorithm that, given an initial configuration (P_1, P_2, ..., P_k), decides if it is a winning configuration - Prepare a polynomial-time algorithm that decides if it is a winning configuration.

  The bookstore wants you to make an object-oriented model

student bookstore at pleasant creek community college situation the bookstore staff at pleasant creek community college

  How use of asnychronous javascript and xml impacts

Assignments one and six of this course are closely related. The 6th assignment involves writing a research report (more specifically, a literature review) on a topic related to web data management. To help you start, this first assignment is meant..

  Evaluate total annual compensation of a salesperson

Write a Java application using NetBeans Integrated Development Environment (IDE) that calculates the total annual compensation of a salesperson. Consider the following factors: A salesperson will earn a fixed salary of $45,000

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