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)]
Topics to discuss
Can you give us sample grades? Yes. After the first exam.
In Scheme, a predicate is a function that returns true or false. even?
exact? list? color? = equal? eq?
In Java, a Predicate is an object that (1) implements the Predicate interface and (2) includes a method test(T val).
Predicate is really java.util.function.Predicate and it's a generic
interface.
We have three ways of making these kinds of objects.
Examples
public class Even
implements Predicate<Integer>
{
public boolean test(Integer val)
{
return (val % 2) == 0;
} // test(Integer)
} // class Even
Somewhere else in my code ...
Predicate<Integer> even = new Even();
Anonymous inner classes
Predicate<Integer> even = new Predicate<Integer>() {
public boolean test(Integer val)
{
return (val % 2) == 0;
} // test(Integer)
};
Anonymous procedures
Predicate<Integer> even = (val) -> (val % 2) == 0;
Predicate<Integer> even = (val) -> { return (val % 2) == 0; }
Let's look at a more complex example
@FunctionalInterface
public interface ArrayManipulator<T>
{
public T manipulate(T[] vals, int i);
} // ArrayManipulator
ArrayManipulator<Integer> albert = (larray, x) -> { return larray[x]; }
What is the idea of Big O?
How do you do the analysis?
Count steps!
sum = 0;
int len = lst.length();
for (i = 0; i < len; i++)
{
sum += lst.get(i);
} // for
return sum
Count the repetitions: n
Let's suppose we just tried to count each time through
1 + 2 + 3 + 4 + ... + n = n(n+1)/2 = n^2/2 + 1/2 is in O(n^2)