Algorithms and OOD (CSC 207 2014S) : EBoards
Primary: [Front Door] [Schedule] - [Academic Honesty] [Disabilities] [Email] - [FAQ] [Teaching & Learning] [Grading] [Rubric] - [Calendar]
Current: [Assignment] [EBoard] [Lab] [Outline] [Reading]
Sections: [Assignments] [EBoards] [Examples] [Handouts] [Labs] [Outlines] [Partners] [Readings]
Reference: [Java 7 API] [Java Code Conventions] [GNU Code Conventions]
Related Courses: [CSC 152 2006S (Rebelsky)] [CSC 207 2013F (Rebelsky)] [CSC 207 2013S (Walker)] [CSC 207 2011S (Weinman)]
Misc: [SamR] [Glimmer Labs] [CS@Grinnell] [Grinnell] [Issue Tracker (Course)] [Issue Tracker (Textbook)]
Overview
Choose your own partners. You may also work alone. You will be tested on many of these topics, so "divide and conquer" is not a good approach.
Part one: Solve some recurrence relations.
Part two: Implement Dutch National Flag, using invariants.
Assumption:
public interface Classifier<T>
{
/**
* Classify val into one of three categories, which we call
* "red", "white", and "blue" for convenience. If val is red,
* returns a negative number. If val is white, returns zero.
* If val is blue, returns a positive number.
*/
public int classify(T val);
} // interface Classifier
or
public interface StringClassifier
{
/**
* Classify val into one of three categories, which we call
* "red", "white", and "blue" for convenience. If val is red,
* returns a negative number. If val is white, returns zero.
* If val is blue, returns a positive number.
*/
public int classify(String val);
} // interface StringClassifier
or
public interface StringClassifier
implements Classifier<String>
{
} // interface StringClassifier
Part three: Implement Skip lists of strings, using invariants.
Interface
public interface StringSet
{
/**
* Determine if the set contains a particular string.
*/
public boolean contains(String str);
/**
* Add an element to the set.
*
* @post contains(str)
*/
public void add(String str);
/**
* Remove an element from the set.
*
* @post !contains(str)
*/
public void remove(String str);
} // interface StringSet
Part four: Implement iterative logn exponentiation, using invariants
/**
* Find the index of val in values.
*/
public static int binarySearch(int[] values, int val)
{
int lb = 0;
int ub = values.length;
// Invariant A: for all i, 0 <= i < lb, values[i] < val
// Invariant B: for all i, ub <= i < length, values[i] > val
while ((ub - lb) > 0)
{
int mid = average(lb, ub);
if (values[mid] < val)
lb = mid+1;
else if (values[mid] > val)
ub = mid;
else
return mid;
} // while
// At this point
// Invariant A: for all i, 0 <= i < lb, values[i] < val
// Invariant B: for all i, ub <= i < length, values[i] > val
// lb >= ub
// The element is not there
throw new NotFound();
} // binarySearch(int[], int)
Primary: [Front Door] [Schedule] - [Academic Honesty] [Disabilities] [Email] - [FAQ] [Teaching & Learning] [Grading] [Rubric] - [Calendar]
Current: [Assignment] [EBoard] [Lab] [Outline] [Reading]
Sections: [Assignments] [EBoards] [Examples] [Handouts] [Labs] [Outlines] [Partners] [Readings]
Reference: [Java 7 API] [Java Code Conventions] [GNU Code Conventions]
Related Courses: [CSC 152 2006S (Rebelsky)] [CSC 207 2013F (Rebelsky)] [CSC 207 2013S (Walker)] [CSC 207 2011S (Weinman)]
Misc: [SamR] [Glimmer Labs] [CS@Grinnell] [Grinnell] [Issue Tracker (Course)] [Issue Tracker (Textbook)]
Copyright (c) 2013-14 Samuel A. Rebelsky.
This work is licensed under a Creative Commons Attribution 3.0 Unported License. To view a copy of this
license, visit http://creativecommons.org/licenses/by/3.0/
or send a letter to Creative Commons, 543 Howard Street, 5th Floor,
San Francisco, California, 94105, USA.