Docsity

Solved Problems on Programming in Data Structures - Assignment | CMSC 221, Assignments of Data Structures and Algorithms

Toggle sidebar
bg1
Page 1 of 2
CS301: Programming Assignment 2
Due: 5:00pm, Friday, Sept. 19
You are expected to complete this program individually. See the syllabus for information about
how you can help your classmates or seek help for various problems.
Each file should contain your name, the name of the file, and the assignment in a comment
at the top of the file.
Develop and test a class that is a binary search tree where each node contains string data. Your
solution will probably consist of four files if you follow the model of the linked list class
discussed during lecture. Recall that a BST has the property that an inorder traversal produces
the values in sorted order. Your class should be called stringBST and should provide the
following public methods:
• stringBST( ) - a zero parameter constructor
• void insert (string) - add a new string to the BST in the appropriate place
• void remove (string) - remove the specified string from the BST, preserving the
BST property.
• bool lookup(string) - returns a bool value, true if the string occurs in the tree and
false if it doesn't.
• void inorder( ) - displays the contents of the tree using an inorder traversal.
You can provide other methods if you want, but please be sure that these methods have exactly
the signatures shown above, so I can run my test driver against your class. It is acceptable for this
program to modify Java code that you saw in CMSC 221 to convert it to C++. Remember, the
remove operation is complicated, so you may want to consult your 221 notes or textbook to
refresh your memory on how it works.
You must also write and turn in a test driver program. For this project, your test driver should not
be interactive; running it should conduct a series of tests and print out the results in an easy-to-
read fashion. Remember the following things about designing test drivers:
1. Always test extreme cases. Test methods on an empty tree to be sure they fail gracefully. In
structures that have an inherent limit on capacity, test what happens if you try to exceed that
capacity.
2. Whenever possible, include in the output of your tester what the expected output should be.
This makes it easy for you or someone else (i.e. me) to tell if your program is doing what it
ought to.
3. Be sure you test all methods in as many different situations as you can think of.
4. For dynamic structures, be sure that things still work correctly after you have filled and then
completely emptied the structure again. (This is to make sure any special cases related to
removing the last item work correctly.)
5. Comment the test driver to indicate your testing strategy and what each case is meant to test.
This is a record of your thought process on how best to test the class.
Your test driver program should be called testBST.cpp.
pf2

Partial preview of the text

Download Solved Problems on Programming in Data Structures - Assignment | CMSC 221 and more Assignments Data Structures and Algorithms in PDF only on Docsity!

Page 1 of 2

CS301: Programming Assignment 2

Due: 5:00pm, Friday, Sept. 19

You are expected to complete this program individually. See the syllabus for information about how you can help your classmates or seek help for various problems.

Each file should contain your name, the name of the file, and the assignment in a comment at the top of the file.

Develop and test a class that is a binary search tree where each node contains string data. Your solution will probably consist of four files if you follow the model of the linked list class discussed during lecture. Recall that a BST has the property that an inorder traversal produces the values in sorted order. Your class should be called stringBST and should provide the following public methods:

  • stringBST( ) - a zero parameter constructor
  • void insert (string) - add a new string to the BST in the appropriate place
  • void remove (string) - remove the specified string from the BST, preserving the BST property.
  • bool lookup(string) - returns a bool value, true if the string occurs in the tree and false if it doesn't.
  • void inorder( ) - displays the contents of the tree using an inorder traversal.

You can provide other methods if you want, but please be sure that these methods have exactly the signatures shown above, so I can run my test driver against your class. It is acceptable for this program to modify Java code that you saw in CMSC 221 to convert it to C++. Remember, the remove operation is complicated, so you may want to consult your 221 notes or textbook to refresh your memory on how it works.

You must also write and turn in a test driver program. For this project, your test driver should not be interactive; running it should conduct a series of tests and print out the results in an easy-to- read fashion. Remember the following things about designing test drivers:

  1. Always test extreme cases. Test methods on an empty tree to be sure they fail gracefully. In structures that have an inherent limit on capacity, test what happens if you try to exceed that capacity.
  2. Whenever possible, include in the output of your tester what the expected output should be. This makes it easy for you or someone else (i.e. me) to tell if your program is doing what it ought to.
  3. Be sure you test all methods in as many different situations as you can think of.
  4. For dynamic structures, be sure that things still work correctly after you have filled and then completely emptied the structure again. (This is to make sure any special cases related to removing the last item work correctly.)
  5. Comment the test driver to indicate your testing strategy and what each case is meant to test. This is a record of your thought process on how best to test the class.

Your test driver program should be called testBST.cpp.

Page 2 of 2

Extra credit: modify your BST to use templates as described in the class notes to create a BST class that can be used to store data of any type. Be sure to change the names of your files (and BST class) so that your extra credit submission doesn't conflict with the files from program 4.

Turn-in instructions

You will turn in your programs by running a script on the unix system that will copy your files into my account. For the first three programs, in a terminal window where you have cd'ed into the directory containing your source program, type:

~lbarnett/share/cs301_bst

You'll need to do this once for each one of the files. Don't forget to send me your test driver!

Grading notes

This time, I won't just be commenting on your test driver, I'll actually be deducting points for deficiencies in it, so don't just leave it until the last minute. In fact, it's probably a better idea to plan your test cases and write your test driver first. I'll also be paying attention to appropriate comments both in the class declaration (.h file) and in the bodies of the methods in your implementation file (.cpp file).