Saint Louis University |
Computer Science 180
|
Dept. of Math & Computer Science |
Please see the general programming webpage for details about the programming environment for this course, guidelines for programming style, and details on electronic submission of assignments.
For this assignment, you must work individually in regard to the design and implementation of your project.
Please make sure you adhere to the policies on academic integrity in this regard.
The files you may need for this assignment can be downloaded here.
Our textbook provides a simple version of a binary search tree with a find function that looks for an exact match for a target item. More generally, search trees are a very powerful concept which can be used to provide a great deal more functionality. They are used in databases for finding exact matches and partial matches.
For this assignment, we will develop a program which keeps track of people's birthdays, allowing us to perform searches based on name or birthdate, including partial matches. From a technical standpoint, we will rely upon two separate search trees which use strings as the data type. You will be repsonsible for rewriting the find method so that it identifies all entries of a tree whose string begins with a given query string.
We will leave it to you to develop the precise algorithmic intuition for this goal. As an example, consider the tree pictured in Figure 8.14 of our text on page 468. How might you search for all entries which begin with the substring "m"? All entries which begin with the substring "th"?
In the original version of find, there could be at most one answer (as duplicates are not allowed in the tree). For this reason, the signature of the function was designed to return a pointer to an item (with NULL returned in the case no match was found).
For this assignment, there may be many possible matches to a query. Rather than return those directly, we have chosen the following signature and semantics.
/** Find all entries which contain target as a prefix. @param target The item sought @param results An initially empty vector in which results should be pushed */ void find(const Item_Type& target, std::vector<Item_Type>& results) const;The caller provides a reference to an initially empty vector. The responsibility of the function is to push all matching results (if any) onto the vector.
As usually, we are providing a driver and a makefile to help with some mundane details. Our driver is called bday and can be used to insert new people into the database as well as to query the database (for simplicity, we are not worrying about erasing entries).
Most significantly, our driver actually makes use of two different
instances of the Binary_Search_Tree class: one which is used
for querying by name and another when querying by birthdate. It does
this by making clever use of data strings. As an example, consider
Jack Nicholson who was born on April 22, 1937. When dealing with
the bday-based tree, we insert the string
However this technique is useless when trying to (efficiently) locate
Jack Nicholson's birthday. For this reason, a second tree is created
which is based upon names, with strings of the form
Our driver will allow you to hand enter individual entries for small-scale testing. However for large-scale testing of efficiency, we have created a text file with nearly 200,000 birthdays (mostly celebrities). We are distributing a link to this fulllist file with the project, and the driver allows it to be loaded.
Though we have not explored this class very seriously, documentation on it is provided in Chapter P.8 of our text. You may either check for partial matches character-by-character with your own logic, or by taking advantage of the existing methods afforded by the class.
All such files can be downloaded here.
BTNode.h, Binary_Tree.h, Binary_Search_Tree.h
These are the original files based upon the code from the
textbook. You should be modifying Binary_Search_Tree.h
appropriately.
bday.cpp, MenuDriver.cpp, MenuDriver.tcc, MenuDriver.h
You should not modify these file.
These support the main driver for testing your code.
As was the case with previous assignments, it is a low-frill,
menu-driven user interface, taking its input from the keyboard
by default, but reading input from a file instead, if you
provide the filename as a runtime argument.
makefile
This makefile should allow you to rebuild your project by
simply typing 'make' rather than in invoking the compiler
directly.
Binary_Search_Tree.h
We expect that this is the only code file you will modify.
If you do create or modify others, please submit those as well.
Readme File
A brief summary of your program, and any further comments you
wish to make to the grader.
The assignment is worth 10 points.