CISC 280 review sheet for second midterm exam, April 17, 2001

Exam covers all of chapter 2 except sections 2.3.4 (Huffman codes) and 2.5.3 (symbolic algebra).

sample questions

  1. What is a recognizer? __________
  2. What is a constructor? __________
  3. What is a proper list? __________
  4. What is a generic operator? __________

    The following apply to the lists L = ((1 2) (3 4)) and M = (5 6 7).
  5. (append L M) returns __________.
  6. (list L M) returns __________.
  7. (cons L M) returns __________.
  8. (cons (list L (+ 1 3)) (append (list M) M)) returns __________.
  9. (cdr (car L)) returns __________.
  10. (length (list L M L L M)) returns __________.

  11. Write (reverse L), the procedure that returns a list which has the items of L in it, but in reverse order.

  12. Write a procedure split which takes a list as argument and returns a list of length 2. The two items in this output list are lists. The first one is the list of all the elements of the input list that are in odd numbered positions. The second list is all the elements in even numbered positions.
    > (split (list 1 2 3 4 5 6 7 8 9 0))  ; input may have even length
    ---> ((1 3 5 7 9) (2 4 6 8 0))
    
    > (split (list 1 2 3))  ; input may have odd length
    ---> ((1 3) (2))
    
    > (split (list 1))  ; input may be short
    ---> ((1) ())
    
    > (split '() )  ; input may be very short
    ---> (() ())
    
    > (split (list "a" 1 "b" 77 (* 2 4) "c" '(1 2))) ; it doesn't matter what's in the list 
    ---> (("a" "b" 8 (1 2)) (1 77 "c"))
    

    Stuff on painters

  13. Write a painter (named "en") to draw the letter "N" with its vertical bars ON the side edges of the frame.
  14. Write a painter to draw this figure:
  15. What does this-painter draw?
    (define this-painter (beside (beside en (flip-vert en)) en) )
    
  16. Define a procedure (mirror p:Painter) that produces a painter that draws p twice, inverted, flip-vert, in the top half and unchanged in the bottom half of the frame.
  17. Define a procedure (circus-mirror u:UPO p:Painter) that produces a painter that draws p twice, once with u applied to p in the top half, and once, unchanged, in the bottom half of the frame. (UPO means unary painter operator.)
  18. Define a procedure (new-mirror u:UPO) that produces a UPO so that ((new-mirror u) p) is a painter that draws the same thing as (circus-mirror u p).

    Stuff on sets

  19. Write an efficient procedure to form the union of two sets of numbers represented as sorted lists.
  20. What advantages does the sorted tree set representation have over the sorted list representation? What advantages does the sorted list representation have over the sorted tree representation?
  21. In the following code join-em is a procedure which (like append) takes two lists and forms the list consisting of all the elements in the first list followed by all the elements in the second list. What difference does it make in the number of steps to do tree->list on a tree T with n nodes if join-em is a one step procedure or is a k step procedure, where k is the number of items in the first list?
    (define (tree->list T)
      (if (empty-tree? T)
          '()
          (join-em (tree->list (left-branch T))
    	       (cons (node-value T) 
    		     (tree->list (right-branch T)) )) ))
    
  22. Mercy hospital and the VA hospital have decided to use a common system to support their patient records. Each hospital keeps a record on new patients consisting of the patient's name, date of admission, and diagnosis. However, Mercy uses a list of the form (name date diag), whereas VA uses (diag name date). In each hospital, many programs deal with these records, so it is not possible to simply change one to conform to the other. To handle the combined record keeping system, it is necessary to provide the constructors make-Mercy-record and make-VA-record and provide the generic selectors name, date, and diag.

    Sketch how you might use data-directed programming to do this, using manifest type and using put and get on a table of procedures.


Here is a quick summary of some procedures studied and other terminology,

Pairs: car cdr cons pair? null?

Uses of pairs abstraction barriers - levels from basic scheme up to application functions

Sequences (lists): nth length list append reverse list?

Symbols and quote '

Symbolic differentition: Expressions are naturally processed using tree recursion. Simplification is an issue that Make-sum, etc can handle.

rational numbers: interval arithmetic:

List processing: (map f L) (filter p? L)

More list processing: (flatten L) (extent L)

Painters: segments->painter,
Painter ops: transform-painter,
unary ops: flip-vert, rotate90, erase, etc.
binary ops: beside, below,
higher order ops: square-of-four,
recursive ops: right-split, corner-split, up-split, square-limit,

Frames: constructors and selectors

Multiple representations, Manifest type, Data directed programming

Some good exercises from chapter 2 are: 2.18, 2.21, 2.22, 2.23, 2.24