CS3240: Data Structures and Algorithms

Binary Search of Sorted List Exercise

PEER GRADED

due Feb. 7

In this exercise you will implement the binary search algorithm of a Sorted List. You will create a simple console applicaton that will promt the user for BOTH the TYPE (you must support both int and strings through the use of templates and query the user during the run of the program what type they wish) and the elements to put into the list and after this the program will enter a loop asking the user for the value they wish to search for. As search is taking place with the binary search algorithm, print each array element vistited to the screen (both the index and the value stored there). You should also have an option to exit the program. Demonstrate program.

Note

1) You need to use Templates in the implementation List. It should be array based but, use templates so that the contents stored could change from say int to float or string. You must make a class called SSortedList. This is where you will make use of Templates - note that it also must be part of the operations of this class also as appropriate.

2) Make the array declared as the template type and the size of it should be passed to the constructor of SSortedList that takes also as input an assorted array of they type to initilize the values. Hence the constructor will dynamically allocate memory for its private array of the template type and do an array copy.

Template <class T> SSortedList<T>::SSortedList(int size, T start_array){

          //step1 - dyanmically allocate array list that is private variable in the
         //              SSortedList (this) class

         // step 2 - copy start_array into the array list of this SSortedList class


}

3) You will need to create a Main Program called TestBinarySearch.cpp that will let the user (see description above) create an instance of a SSortedList of different data types through its use of templates
(NOTE: I will test this program by attempting to create both int and string Sorted lists.)
Next this program will to perform binary search on the instance of the SSortedList adhering to requirements above about printing out information about the search and during it. MAKE this nicesly formatted so it is easy to understand. Binary Search algorithm is implemented as an operation of the SSortedList as described here. Note that when you call this member function you should print out if found or not and if found the index value in the array where it was found.

void  SSortedList::BinarySearch ( T  item,   bool&  found , int& index)  


>>this must be passed the item that the user wishes to search for,  if found the found variable is set to 
true else it is false. if found the index will be set to the index of the array location where it was found
if not found it will return -1 for the index value.

NOTE: you must create your own data structure and algorithm code and not use code found in STL or other sources.

Deliverables

  1. Show in class to peer grader
  2. Upload code in a zipped file called code.zip to blackboard Image Array Exercise


Evaluation

  1. This exercise will be graded by a peer (fellow student) during class. You must be present on the due date of this exercise hence to get credit on it and to participate in the grading of another student's work. (Only Valid DOCUMENTED Excuse will be allowed for missed peer grading and must be approved by instructor--evaluation process to be determined by instructor)


  2. During the class session when peer grading is started, the professor will disscuss a "correct" solution with the class and you will use this and guidelines presented and discussed to grade the student's work. FOR THIS ASSIGNMENT you will demonstrate your work to your grader

  3. As part of this we will explore different solutions done by students and unexpected logic errors and syntax errors.

Evaluation Guidelines

ITEM Points Range
Sorted List

20 points (yes the items below add up to more than 20 points as they are points off)

  • -5 points did not use templates as requred when implementing your OWN list class.
  • -5 points did not use a class named SSortedList to represent the Sorted List data structure
  • -5 points the constructor of the SSortedList class should take the number of elements and an array of template type T (see above) to store in an array based implementation of the sorted list data structure.
  • -10 points do not have data sorted in list during insertion as required of a sorted list.
Binary Search of Sorted List

25 points (yes the items below add up to more than 25 points as they are points off)

  • -3 points do not print each item to the screen as the binary search algorithm visits each new element looking for the search item specified by the user.
  • -5 points did not make it a member function of the class SSortedList with the signature described above.
  • -20 points did not implement Binary Search correctly.
Main Program

5 points (yes the items below add up to more than 5 points as they are points off)

  • -3 points do not ask user whether or not the items are int or strings
  • -2 points do not ask user how many items they want to store in list and consequently ask user for that many items and store them in your data structure
  • -2 points do not ask user for the item they then want to search for and call the binary search algorithm
  • -2 points you did not call main program TestBinarySearch.cpp

 

© Lynne Grewe