| CIT 594 Final Exam Spring 2003, Dave Matuszek |
Name _______________________________________
|
135 points total. Please keep all answers brief and to the point; try to stay within the space provided.
(EVAL (QUOTE (CDR (QUOTE (A B C)))))
? if (myHashSet.contains(new Position(i, j))
System.out.println("Been there, done that.");
n, the size of the
problem.)
static int euclid(int x, int y) {
assert x > 0 && y > 0;
if (x > y) return euclid(x - y, y);
if (x < y) return euclid(x, y - x);
return y;
}
|
On average, and in the worst case, it will be O(n). There are various ways to choose n. The simplest (though not the most accurate) is just to choose n as the larger of x and y. |
euclid
method given above. static int euclid(int x, int y) {
assert x > 0 && y > 0;
while (x != y) {
if (x > y) x = x - y;
else y = y - x;
}
return y;
}
![]() |
![]() |
3/4. Fraction by specifying
Java method (or constructor) headers for each operation. Be sure
to include any essential constructors or methods.|
(C) public Fraction(int numerator,
int denominator) |
(A) public boolean isNegative() |
Fraction objects
mutable or immutable, and why you did it that way.Fraction class should you raise
an exception?
- Preorder: A B C D E
- Inorder: B D E C A
- Postorder: E D C B A