YCP Logo Lab 12: Generic algorithms

Due: Tuesday, Oct 28th by 11:59 PM

Getting Started

Download CS201_Lab12.zip. Import it into Eclipse (File->Import...->Existing Projects into Workspace->Archive File.) You should see a project called CS201_Lab12 in the package explorer.

Your Task

Your task is to implement the five static methods defined in the Algorithms class.

static<E extends Comparable<E>> E findMin(Collection<E> c)
This method should return the minimum (smallest) value in the given Collection. Since each element belongs to a class implementing the Comparable<E> interface, you can use the compareTo method to compare element values.
static<E extends Comparable<E>> E findMax(Collection<E> c)
Like findMin above, but return the maximum element value instead of the minimum.
static<E> E findMin(Collection<E> c, Comparator<E> comp)
Like the version of findMin that just takes a Collection, but uses the Comparator parameter to do the element comparison.
static<E> E findMax(Collection<E> c, Comparator<E> comp)
Like findMin above, but return the maximum element value instead of the minimum.
static<E> int sequentialSearch(List<E> list, E searchVal)
Do a sequential search of the given List. Return the index of the first occurrence of an element comparing as equal to searchVal, or -1 if searchVal does not occur in the list. Use the equals method to do the comparisons.

A JUnit test class, AlgorithmsTest, is provided.

Super-duper extra challenge

Optional: if you finish the above tasks, and your brain isn't completely twisted in knots, rewrite the four findMin and findMax methods so that three of them are implemented by making a call to the fourth.

Hint: Leave your static<E> E findMin(Collection<E> c, Comparator<E> comp) as it is. Change the other methods to call it.

Another hint: Defining one or more new Comparator classes will help.

Let me know if you figure this one out. I may award a prize.


When you are done, save the project (CS201_Lab12) to a zip file by right-clicking it and choosing

Export...->Archive File

Upload the saved zip file to the Marmoset server as lab12. The server URL is