Construct a huffman code tree

Assignment Help JAVA Programming
Reference no: EM13807082

Review Questions

1. Draw the tree that would be formed by inserting the words in this question into a binary search tree. Use lowercase letters.

2. Show all three traversals of this tree.

3. Show the tree from Question 1 after removing draw, by, and letters in that order.

4. Answer Question 1, but store the words in a heap instead of a binary search tree.

5. Given the following frequency table, construct a Huffman code tree. Show the initial priority queue and all changes in its state as the tree is constructed.

Symbol Frequency
x 34
y 28
w 20
a 10
b 8
c 5

Programming Projects

1. Assume that a class Expressi onTree has a data field that is a BinaryTree. Write an instance method to evaluate an expression stored in a binary tree whose nodes contain

Review Questions

1. Show where the following keys would be placed in a hash table of size 5 using open addressing: 1000, 1002, 1007, 1003. Where would these keys be after rehashing to a table of size 11?

2. Answer Question 1 for a hash table that uses chaining.

3. Write a toString method for class Hashtabl eOpen. This method should display each table element that is not null and is not deleted.

4. Class Hashtabl eChain uses the class Li nkedlis t, which is implemented as a double-linked list. Write the put method using a single linked list to hold elements that hash to the sane index.

5. Write the get method for the class in Question 4.

6. Write the reffove method for the class in Question 4.

7. Write inner class Ent rySet for the class in Question 4 (see Listing. 7.11).

Programming Projects

1. Complete all methods of class HuffmanTree and test them out using a document file and a Java source file on your computer. You can download class Bi tSt ring from the Web site for this textbook.

2. the a HashNap to store the frequency counts for all the words in a large text document. When vnn arc done ilicrdav the contents of this Hachlian Nm create a we view of the

Programming Projects

I. Assume that a class ExpressionTree has a data field that is a BinaryTree. Write an instance method to evaluate an expression stored in a binary tree whose nodes contain either integer values (stored in Integer objects) or operators (stored in Character objects). Your method should implement the following algorithm.

Algorithm to Evaluate an Expression Tree

1. if the root node is an Integer object

2. Return the integer value.

3. else if the root node is a Character object

4. Let leftVal be the value obtained by recursively applying this algorithm to the left subtree.

5. Let rightVal be the value obtained by recursively applying this algorithm to the right subtree.

6. Return the value obtained by applying the operator in the root node to leftVal and rightVal.

Use method readBi naryTree to read the expression tree.

2. Write an application to test the HuffnanTree class. Your application will need to read a text file and build a frequency table for the characters occurring in that file. Once that table is built, create a Huffman code tree and then a string consisting of '0' and '1' digit characters that represents the code string for that file. Read that string back in and re-create the contents of the original file.

3. Solve Programming Project 4 in Chapter 4, 'Queues," using the class Priori tyQueue.

4. Build a generic Huffmaniree.cT> class such that the symbol type T is specified when the tree
is created. Test this class by using it to encode the words in your favorite nursery rhyme.

5. Write clone, size, and height methods for the BinaryTree class.

Programming Projects

1. Complete all methods of class HuffmanTree and test them out using a document file and a Java source file on your computer. You can download class Bi tStri ng from the Web site for this textbook.

2. Use a FleshMap to store the frequency counts for all the words in a large text doctunent. When you are done, display the contents of this HashMap. Next, create a set view of the Map and store its contents in an array. Then sort the array based on key value and display it. Finally, sort the array in decreasing order by frequency and display it.

3. Solve Project 2 using a TreeMap. You can display the words in key sequence without performing a sort.

4. Modify Project 2 to save the line numbers for every occurrence of a word as well as the count.

5. (Based on an example in Brian W. Kernighan and Rob Pike, The Practice of Programming, Addison-Wesley, 1999) We want to generate "random text" in the style of another author. Your first task is to collect a group of prefix strings of two words that occur in a text file and associate them with a list of suffix strings using a Map. For example, the text for Charles Dickens' A Christmas Carol contains the four phrases:

Marley was dead: to begin with. Marley was as dead as a door-nail. Marley was as dead as a door-nail. Marley was dead.

The prefix string "Marley was" would be associated with the ArrayList containing the four suffix strings "dead: ", "as", "as", "dead. ''. You must go through the text and examine each successive pair of two-word strings to see whether that pair is already in the map as a key. If so, add the next word to the ArrayLi st that is the value for that prefix string. For example, in examining the first two sentences shown, you would first add to the entry ("Harley was", ArrayLi st "dead :"). Next you would add the entry ("was dead", ArrayList "as"). Next you would add the entry ("dead as", ArrayList "al, and so on.

Reference no: EM13807082

Questions Cloud

Example inventory list for staff : The warehouse manager asked you to create an example inventory list for his staff. The inventory list is a comprehensive chart that lists all of the company's internal resources: equipment, machines, technology, furniture, office supplies, etc.
Iranian theocracy : Iranian Theocracy
Analyze how coppa and cipa are similar : Analyze how COPPA and CIPA are similar and how they are different, and explain why there is a need for two (2) different acts. Describe what you believe are the most challenging elements of both COPPA and CIPA to implement in order to be compliant
Problems based on concept data is discrete or continuous. : Describe a recent Gallup poll. Be sure to include the results of the poll, how the poll was conducted, and what the results will be used for
Construct a huffman code tree : Draw the tree that would be formed by inserting the words in this question into a binary search tree and construct a Huffman code tree. Show the initial priority queue and all changes in its state as the tree is constructed.
What impact did each book have on your thinking : What impact did each book have on your thinking
Direct the activities of their employees : Communication and motivation are important skills for managers to use to direct the activities of their employees. These tools are used to help connect employees' efforts to company strategies.
What is the probability that the number of fans at any given : In its third year, the Liberty Football League averaged 16,050 fans per game, with a standard deviation of 2,050 fans. According to these data, a. What is the probability that the number of fans at any given game was greater than 20,000?
Discuss what are the three types of casual relationships : Discuss what the three types of "Casual Relationships" are and why they are so important? Discuss "Who is a Moral Person" and why that is important to you, and to society/civilization?

Reviews

Write a Review

JAVA Programming Questions & Answers

  Write a method, insertat that takes four parameters

Write a method, insertAt that takes four parameters

  Write a program that specializes in solving the equations

Write a program that specializes in solving the equations Ax=b by Doolittle's decomposition method, where a is the HIbber matrix of arbitrary size nxn and

  Write a loop that will print out the value

Given the subsequent code segment that reads in a String str - Write a loop that will print out the value entered into str in reverse.

  Java class to accept a user-s hourly rate of pay

Write a class that accepts a user's hourly rate of pay and the number of hours worked. Display the user's gross pay, the withholding tax (15% of gross pay), and the net pay (gross pay - withholding).

  What value would be returned from call to its size() method

If a collection stores 5 objects, what value would be returned from a call to its size() method?

  Java application to carry out additions and subtractions

Design a Java application to carry out additions and subtractions for numbers of any length. A number is represented as an object which includes a sign and two strings for the whole and decimal parts of the number.

  Write ijvm program to multiply two hexadecimal numbers

Write the IJVM program that multiplies two (hexadecimal) numbers. The user inputs the hex numbers and the result is printed out. The program then accepts another pair of numbers.

  Write a program that assigns seats on an airplane

Prepare a program that teaches arithmetic to a young child. The program tests subtraction and addition. Write a program that assigns seats on an airplane.

  Create wheel 360 degree

You have to create wheel, 360 degree. That is numbered 0-36. it is supposed to be spun, and randomly lands on one of the numbers.

  Create a class named student that has three member variables

Create a class named Student that has three member variables

  Create a constructor in the subclass why

Assume there is a base class with multiple constructors, if the subclass inherits from the base class, do we need to create a constructor in the subclass? Why?

  List data structures to be used in solution

write a program that will prompt the user for an input file name to read from. The Input file will consist of records made up of first name, last name and an account balance of individuals and store the individuals in an ArrayList.

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