Algorithms and OOD (CSC 207 2014F) : EBoards
Primary: [Front Door] [Schedule] - [Academic Honesty] [Disabilities] [Email] - [Learning Outcomes] [FAQ] [Teaching & Learning] [Grading] [Rubric] - [Calendar]
Current: [Assignment] [EBoard] [Lab] [Outline] [Reading]
Sections: [Assignments] [EBoards] [Examples] [Handouts] [Labs] [Outlines] [Readings]
Reference: [Student-Curated Resources] [Java 8 API] [Java 8 Tutorials] [Code Conventions]
Related Courses: [CSC 152 2006S (Rebelsky)] [CSC 207 2014S (Rebelsky)] [CSC 207 2014F (Walker)] [CSC 207 2011S (Weinman)]
Misc: [Submit Questions] - [SamR] [Glimmer Labs] [CS@Grinnell] [Grinnell] - [Issue Tracker (Course)] [Issue Tracker (Textbook)]
Overview
For the interface, should it use a Web client and prompt for the site?
Yes
Can it just do one iteration through the list?
Yes
Can we return a new UshahidiTestingClient or something similar for
extra 2?
Yes
Can we do without the array for extra 2?
Yes
Don't we need clients for extra 2?
Yes
A typical signature
public static <T> T search(T val, List<T> values, Predicate<T> ok)
Do we need both the value and the predicate?
public static <T> T search(List<T> values, Predicate<T> ok)
If we're doing binary search, don't we need an order?
/**
* Search for val in vals. Return the index.
*
* @pre
* vals is sorted by order. order.compare(vals.get(i),vals.get(i+1)) <= 0 for all reasonable i
*/
public static <T> int binarySearch(Vector<T> values, Comparator<T> order, T val)
binarySearch(val, values, order
return binarySearch(val, values, 0, values.length, order)
// binary search in a subarray
binarySearch(val, values, lb, ub, order)
if (lb >= ub)
thrown an exception
else
mid = average(lb,ub)
if order.compare(values[mid], val) < 0
return binarySearch(val,values, mid+1, ub, order)
else if order.compare(values[mid], val) > 0
return binarySearch(val,values, lb, mid (or mid-1), order)
else
return mid
How long does this take?
time(n) = c + time(n/2)
time(1) = d // no recursion
Given a recurrence relation that defines a function, you can write the function in "closed form" with not recursion. Read the rest in the reading. We'll do more later.
What do you think about using the following method from java.util.Array?
static int[] copyOfRange(int[] original, int from, int to)
How do we test for an exception?
boolean failed = false;
try
{
CodeWeExpectToFail;
}
catch (Exception e)
{
failed = true;
}
if (!failed)
fail("Did not throw an exception in ...");