1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70
|
Overview
Hashing is useful if we are only interested in insert, delete, and find operations; e.g., delete(10) or insert(5) or find(100). But a hash table provides no assistance for searches that depend on the order or rank of an element in a set, e.g., find the smallest element, delete the smallest element, etc. For the latter type of operation, you have learned that priority queues are more appropriate. On the other hand priority queues do not support a general delete operation, e.g., delete(100); they only support deleting the minimum (or maximum) element.
The goals of this programming assignment are
to review your knowledge and understanding of the concepts of file I/O, formatted output, and string parsing with C++;
to give you experience in combining features of multiple data structures in order to accomplish a specific task; and
to get you acquainted with the C++ Standard Template Library (STL) - I recommend cplusplus.com and cppreference.com as solid C++ STL references ...
Description
In this programming assignment, you will develop a “compound” data structure called a Quash, which is composed of both a min-heap (priority queue) and a hash table. The Quash supports insert, delete and lookup operations using its hash component, and a deleteMin operation using its heap component. In particular, each element in a Quash will be inserted in both the heap and the hash table components. Note that to facilitate the two delete operations, you will need to include pointers in both directions between the 2 instances of the element in the heap and in the hash table.
Operations should be executed as follows:
insert(x): Insert element x in both the heap and the hash table components, and link them correctly. Your driver/program (not the operation) should return either “item x successfully inserted” or “item x already present” (no duplicates allowed), depending on the success or failure of the operation.
lookup(x): Use the hash table component to determine if x is in the Quash. Your driver/program should return either “item x found” or “item x not found” after executing this operation.
deleteMin(): Use the heap component to delete the minimum element, and use the pointer to delete the element in the hash table component. Your driver/program should report the key value of the item deleted, such as “min item x deleted,” or an error message such as “empty Quash; no minimum item,” if the Quash is empty.
delete(x): Use the hash table component to determine where x is, delete it from the hash table and use the pointer to delete it from the heap. (Note that you will need to generalize the heap operations to support this “internal,” non-root, delete operation.) Your driver/program should return either “item x successfully deleted” or “item x not found.”
print(): Prints out the hash table as well as the heap (in the array format) on two separate lines, with elements separated by a blank.
Instructions
Your executable will be called quashTest. You will design, implement, and test your implementation of a quash class that implements the Quash data structure described above. Features of your driver/program are described below. All source code should be well-documented (at the least, with your name, brief description of the problem and your implementation, etc.). Solutions with source code that is not documented will receive no credit. All solutions must be submitted by uploading to your turnin directory in the ECC Unix server by the due date and time indicated above. Late submissions will not be accepted, so be sure you upload even partial solutions to receive some partial credit.
Be sure to start working on this assignment early. It is highly recommended that you spend a couple of days fully understanding the problem, perhaps with hand-drawn mock-ups of the data (and data structures) you think you will need to solve this problem, and hand-tracing through the various options to ensure you can provide the required functionality. You may use and modify any of the code available for our class to assist you in implementing your solution. Additionally
familiarize yourself with Dr. J's Coding Standards
you are expected to use the target executable filename given in the sample runs below (Note: No .exe file extension!)
your name must be displayed by your executable each time it is run
your executable must be designed take command-line arguments and must have the following specific implementation requirements:
Assume all elements to be inserted are unsigned integers.
Use the array implementation for the min heap component of your quash class.
Use “modulo 2011” (2011 happens to be the 305th prime number) as your hash function. In general, it would be better to use an internal resize() operation, which doubles the hash table size when the tables becomes too full, and shrinks it when it becomes too empty, using appropriate load factor thresholds for“too full” and “too empty.” In this assignment, the table size will be fixed; hence, inserting more items into an already full table should be rejected.
For collision resolution, use linear probing.
Use a “lazy deletion” method by marking slots in the hash table component as deleted; you may use a boolean flag called deleted to indicate that a slot was once used but is now deleted.
The sole command-line argument to your driver is a text file that contains commands that match the operations on a Quash object. Here is a sample run:
$ quashTest commands.txt
quashTest, by Your_Name_Goes_Here
Reading input file sample.txt ...
item 10 successfully inserted
item 50 successfully inserted
item 76 successfully inserted
Additional messages appear based on commands in commands.txt
$ _
Input text files contain commands that match the operations on a Quash object. Any invalid commands should result in an appropriate error message. Here are the contents of the file commands.txt:
insert 10
insert 50
insert 76
print
lookup 12
insert 12
lookup 12
deleteMin
delete 76
insert 12
deleteMin
lookup 76
print
|