-
Notifications
You must be signed in to change notification settings - Fork 28
Search
Jinho D. Choi edited this page Aug 24, 2016
·
1 revision
- Create a package
edu.emory.mathcs.cs323.search
. - Create an interface
ISearch
undersearch
. - Make a generic type
T extends
Comparable<T>
. - Declare an abstract method
search
. -
@param list
a list containing zero to many keys. -
@param key
a key to be searched. -
@return
the index of the key in the list if exists; otherwise, a negative integer.
- Create classes
LinearSearch
andBinarySearch
undersearch
. - Implement
ISearch
. - Make a generic type
T extends
[Comparable<T>
]. - Override the
search
method in each class for linear and binary search. - For binary search, assume that the input list is sorted in ascending order.
- Assess
LinearSearch
andBinarySearch
using: -
SearchTest#testAccuracy()
. - Compare the speeds of
LinearSearch
andBinarySearch
using: -
SearchTest#compareSpeed()
.
-
Imagine that the following condition didn't exist in
BinarySearch
(lines 45-46).if (beginIndex > endIndex) return -1;
-
Give a list of integers containing more than one key, sorted in ascending order, that would make
BinarySearch
throw an exception or an error. Explain why this would be thrown.
Copyright © 2014-2017 Emory University - All Rights Reserved.