# COMP 250: Introduction to Computer Science Assignment #3 Solved

30.00 \$

Category:
Click Category Button to View Your Next Assignment | Homework

You'll get a download link with a: . ` zip` solution files instantly, after Payment

## Description

5/5 - (2 votes)

Submission Instructions:

Submit a single zipped file A3.zip which contains the modified WordTree.java file, to the myCourses assignment A3 folder. Include your name and student ID number in the comment at the top of the WordTree.java file.Â  Â

In this assignment, you will work on the problem of storing a set of n words in a tree data structure, and a method for efficiently finding all the words that have a given prefix.Â  You should be familiar with the latter problem through the autocomplete feature found on cell phones, web forms, Eclipse. For instance, if you type in â€œaar“, then the autocomplete feature may suggest aardvark, aardvarks, aardwolf, aardwolves, aargh.

By word, we mean a string formed from the set of ASCII characters, specifically alphanumeric characters a-zA-Z.Â Â Â Â Â  See http://www.asciitable.com/ for a list of all ASCII characters.Â Â  Note that ASCII encodes text using one byte or 8 bits per character.

## WordTree Data Structure

Here we define a special kind of rooted tree that we use to efficiently index words by storing their prefixes. The main property of this tree is that each edge corresponds to a character.Â Â  Thus the path from the root of the tree to any node in the tree defines a string.Â  The string defined by each node is a prefix of all strings defined by the descendents of that node.

Below is an example tree. It contains the following words: a, and, ax, dog, door, dot.Â  You will note that the dashed nodes correspond to prefixes in the tree (an, d, do, doo) that are not in our list of words. The tree must also keep track of this distinction by storing for each node whether it corresponds to a word or not.

Note that if C is the set of all possible characters defined at the edges, then each node can have at mostÂ  k = | C | children,Â  where the | C |Â  notation just means the number of elements in set C.

## What You Need To Do

Â

Read the provided code (WordTree.java, A3TesterPosted.java), including the comments which explain what the various methods do.Â Â Â Â  This will take you some time, so go slow and read the code carefully. Â Â Â Note that the WordTree class has a private inner class TreeNode.

For the WordTree class, fill in the missing code for the following methods:

• createChild(), toString() for the inner class TreeNodeÂ Â Â  Â
• getPrefixNode(), insert(),Â  contains(),Â  getListPrefixMatches()

We suggest you implement them in the order listed above.Â Â Â  To get started, you may wish to add a main() method to the WordTree class.Â Â  Eventually you should move on to using the Tester file.Â Â  Donâ€™t forget to delete the main method when you submit !

You may only use Java String methods length() and charAt().Â  In particular, do not use String searching methods such as String.startsWith(),Â  String.substring(), etc.Â Â Â  The point of the assignment is for you to organize and compare strings using this tree data structure.

Only add code in the area where it says to add code.Â Â  The grader may be sensitive to any changes that you make outside that area.Â Â  Any helper methods that you wish to write should be added at the end of the WordTree.java file.

Note that all methods and also the inner class have been given the publicÂ  access modifier.Â Â  This was done to simplify grading.Â Â  As you will learn later in the course, typically one does not make all methods public.

Submit only the file WordTree.javaÂ  as a zip file.Â Â Â  Use the A3TesterPosted.javaÂ  file to test your code.Â  You do not need to submit this tester file.

Good luck and have fun!

• a3-2.zip