CSCI 311 - Spring 2008 - Program 2
Patricia Trees
Dr. Melody Stapleton, Instructor
Shaun McCluskey, Teaching Assistant
Due Date: All Program Components: Monday, April 14, uploaded by midnight
Your TA will provide the final input file(s) to run your program against.
Your are to implement the operations of a Patricia Tree, as discussed in class and posted in the course notes on the web using appropriate C++ classes. Be sure to check your TAs web site frequently for updates and/or modifications to this assignment.
You are to structure your main program to accept and interpret file input with the following format:
You are to have an initially empty tree, i.e. root is NULL. Listed below are the possibilities for the different categories of commands:
You will, of course, need to create a Patricia_Tree class that has at least the following member functions:
Output: Send your output for this program to a file. For inserts, it is an error to insert a duplicate value in the Patricia Tree structure, be sure to notify the user of such an attempt. Tell the user if an operation is successful, as well. Be sure to give appropriate "error" messages back to the user of your program, via the output file. For e.g., if asked to delete a value from the Patricia Tree structure that is not found in the structure, you should reply that the value was not found and so could not be deleted. For the Search operation, as well as returning the appropriate pointer as described above, if the item being sought is found, print out a message that says you found it and what its value is. On the other hand, if the item is not found, print out a message to that effect.
Also Note: You are responsible to write a program that deals with *all cases*. That is, your program should not only *work good on some input files*, it need to work on *all possible* input files. This means it is not your TAs responsibility to give you an input file that allows your program to work. It is your responsibility to write code that cannot be broken by any input file and so will work in all cases. This will be the case for every program you write for this course.
Deletes: Be sure, for a node that have 2 "real" children, to use the Search Predecessor, as discussed in class, and copy over the value of the Search Predecessor in the node to be deleted and then physically delete the Search Predecessor.
Printing: The standard Inorder Traversal for binary trees needs to be modified, since Patricia Trees have no NULL pointers within them. Therefore, your stopping state in a traversal will be the same as it is for searching. That is, when the bit test in the new node being pointed to is the same number or higher than the previous node that pointed to it, then print the value in this "higher or same" bit test node, but there will be no further recursive calls. This does mean that all of the values in the tree will be printed twice. That is OK, since you want to be able to make sure that every node is pointed to by an "up" pointer, as well as a "down" pointer. Where "up" and "down" are referring to the number representing the bit test in a node. Do not print the dummy header, and do print not only the integer value stored in each node, but also the bit test in that node. (For debugging purposes, you might want to intermediately print out the bit string that represents the integer and also the dummy.)
Input: The input file will consist of integers up to 4 digits long. You will need to convert these integers into their binary representations. The highest bit test will be for the highest power of 2 that goes into the integer 9999.
Sample Input:
D 5335
S 3497
P
I 200
I 5000
I 9
I 4957
P
D 9
I 1957
I 8923
I 9999
P
S 9999
D 9999
I 4331
I 4957
D 1300
S 4957
I 4957
P
I 4233
I 5987
I 5555
I 2000
I 8000
I 4000
I 9000
I 9500
I 1100
I 3333
I 7777
I 1111
P
I 639
I 935
I 422
I 10
I 5
I 8
I 56
I 90
P
I 8723
I 9233
I 1876
I 1922
I 1499
P
D 1922
D 1100
D 1111
D 8000
D 9500
P
S 935
S 3333
D 639
D 935
D 5335
S 3497
P
D 200
D 5000
D 9
D 4957
P
D 9
D 1957
D 8923
D 9999
P
S 9999
D 9999
D 4331
D 4957
D 1300
S 4957
D 4957
P
D 4233
D 5987
D 5555
D 2000
D 8000
D 4000
D 9000
D 9500
D 1100
D 3333
D 7777
D 1111
P
D 639
D 935
D 422
D 10
D 5
D 8
D 56
D 90
P
D 8723
D 9233
D 1876
D 1922
D 1499
P