CS 102: Data Structures

Spring 2006


Lab3

Sequential and Binary Search


Introduction

The purpose of this lab is to work with searching algorithms.

To Do

1. Create a record class or storing in a database. A record should include a name and two other pieces of information that are either stored as Integer or Double. Assume that names are unique.

2. Create a database class that stores items of the class from step 1 in an ArrayList. The DB should have the following metods:

     a. add - adds an item in alphabetical order according to its name.
     b. index - returns the index of an item stored, given its name as a parameter. Use binary search.
     c. getRecord - given the name, gets the full record and returns it.
     d. remove - given the name, removes the record with that name.
     e. findXXX - given the value for one of the other fields (XXX) as a parameter, returns an ArrayList of all records with that field matching the parameter.

3. Create a driver class that tests all the operations of your DB.

4. Add a constructor to your database that takes a Java File and reads the records from the file. Add an operation to your database that will write the information to a file. Note: you must select a file format to make this work consistently.

5. For each of the operations in part 2, specify the computational complexity (worst case) in terms of N, the number of things in the database when the operation is executed. You can place this information as a comment with each of the methods in your code.