CISC 280 review sheet for second midterm exam, April 23, 1997

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

sample question types

  • What is a recognizer? __________
  • What is a constructor? __________
  • What is a proper list? __________
  • What is a generic operator? __________

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

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

  • Write a procedure \verb|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
    1. Write a painter (named "en") to draw the letter "N" with its vertical bars ON the side edges of the frame.
    2. Write a painter to draw this figure:
    3. What does this painter draw?
      (define this-painter (beside (beside (beside en (flip-vert en)) en) en))
    4. 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.
    5. 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.)
    6. 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).
    7. What forms of abstraction does the painter language exploit? Discuss (What benefits and costs do you see to this approach? How does this system compare to others you have seen or could imagine?)
  • stuff on sets
    1. Write an efficient procedure to form the union of two sets of numbers represented as sorted lists.
    2. 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?
    3. 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)) )) ))
    
  • 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 \verb|make-Mercy-record| and \verb|make-VA-record| and provide the generic selectors \verb|name|, \verb|date|, and \verb|diag|.
    1. Explain how this can be done using manifest type, but without using a table of procedures (no put and get).
    2. Sketch how you might use data-directed programming, 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. (p> rational numbers: interval arithmetic: (p> List processing: (map f L) (filter p? L) (repeater n) (multilist n) (p> More list processing: (flatten L) (extent L) (p> Painters: segments->painter,
    Painter ops: transform-painter,
    specific transforms: flip-vert, rotate90, erase, etc.
    binary ops: beside, below,
    painter-op ops: square-of-four,
    recursive ops: right-split, corner-split, up-split, square-limit,

    Frames: constructors and selectors

    Painter system ops: draw-line, show.

    Multiple representations Manifest type Data directed programming

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


    saunders@cis.udel.edu