CMP 338: Data Structures & Algorithms
Lehman College, City University of New York
Spring 2015
This Homework Is Due By 11:59 PM on February 8, 2015
Implementation: (15 Points)
In lecture, we reviewed two searching algorithms:
Linear Search
and
Binary Search
Write a Java program that implements both linear search and binary search.
You may implement either the recursive or iterative version of binary sort.
Test Cases: (20 Points)
You must also write a driver program that demonstrates that both searh
search programs work. Your driver should use a sorted list of
10,000,000 numbers. Your driver should time how long each algorithm takes
to search for the following numbers:
500
10,000
100,000
1,000,000
5,000,000
7,000,000
10,000,000
Run each test 10 times and make a table with the running time for each run,
as well as the average and the standard deviation for each algorithm.
Analysis: (15 Points)
Using the tables you created, answer the following questions using complete sentences:
Was Linear Search ever faster than Binary Search? When? Explain.
If both searches report the time as 0 milliseconds for an instance, do they take the
same amount of time? Why or why not?
Which was the faster search overall? Explain.
Please submit the completed assignment on Blackboard. You must submit your Java programs
as a zip file of your Eclipse project. The analysis must be a typed Microsoft Word file.
No other forms of submission will be accepted.