Due 05.Feb.22 (Tue)
Before you tackle the homework, remind yourself of our general hw policies. In addition, here are some Q&A's about this homework.
Reading in Rosen: 1.5 ("Methods of Proving Theorems"), 1.6, 1.7, 7.1 (skim), and 7.3 (digraphs only).
(Extra Credit 2pts) For the set implementation given in Lecture 10, write the functions
;; set-: Set, Set --> Set ;; Return the set-difference of A and B ;; (define (set- A B) ...) ;; cross-product: Set, Set --> Set ;; Return the cartesian cross-product of A and B. ;; NB See text "cartesian product"; ;; this is not the cross-product from 3-d vector calc. ;; (define (cross-product A B) ...)You may write your code in scheme (procedural), scheme (object-oriented), or java. Turn in a hardcopy of your code (including sufficient test cases). If your code does not pass all test cases, say so.
As throughout comp210, good code should strive to meet the definition as closely as possible. (For instance, compare the code for set-union and set-intersection with the book's definition of union and intersection.) If your functions are much longer than two lines (Scheme) or six lines (Java), you are being unnecessarily complicated.
One note: since cartesian products deal with ordered pairs, you'll need to decide how to represent these in your program. You have some latitude on this.
(In general, fixed-length lists or arrays/vectors are perfectly acceptable representations of tuples. Still, distinguish between functions that accept/return tuples from those that work on lists/arrays/vectors -- just as you'd distinguish between functions that return colors vs strings, even if you happen to represent colors as strings of red-green-blue values.)
One remote caution: in scheme, the name "pair?
" is built-in,
but it does not mean a-list-of-exactly-two-elements;
it's actually just another name for cons?
.
(If curious, check help-desk for "improper list".)
Fortunately this shouldn't be an issue;
if you define-struct pair, then the built-in name is
shadowed with the new structure-checking-predicate,
as you'd expect.