{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

Computer Science 61A - Fall 1997 - Harvey - Midterm 2

# Computer Science 61A - Fall 1997 - Harvey - Midterm 2 - CS...

This preview shows pages 1–3. Sign up to view the full content.

CS 61A, Midterm #2, Fall 1997 CS 61A, Fall 1997 Midterm #2 Professor Harvey Problem #1 This problem concerns the tree abstract data type defined by the constructor make-tree, invoked with (make-tree <datum> <children>), and the selectors datum and children. (a) Write the procedure treeify: -The argument to treeify is a nonempty list representing arithmetic computation in infix notation, such as this example: ((3 + 4) * (7 - (2 / 2))) More precisely, a computation is either a number or a list of three elements, in which the first and last are computations and the middle element is a symbol representing an operator (such as +). -The value returned by treeify is a tree in which the branch nodes are operator symbols and the leaf nodes are numbers: * / \ + - / \ / \ 3 4 7 / / \ 2 2 (b) Suppose that the time required for an addition or subtraction is one microsecond, and the time required for a multiplication or a division is five microseconds. + - 1 * / 5 Write a time procedure that takes as its argument a computation tree as produced by treeify, and returns the number of microseconds required to compute the desired value. >(time (treeify '((3 + 4) * (7 - (2 / 2)))) file:///C|/Documents%20and%20Settings/Jason%20Raft. ..-%20Fall%201997%20-%20Harvey%20-%20Midterm%202.htm (1 of 5)1/27/2007 6:27:31 PM

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
CS 61A, Midterm #2, Fall 1997 12 Problem #2 The procedure addup, shown later, takes two arguments: a list of numbers, and a goal number. It returns a list of numbers, a subset of the original list, whose sum is the goal number, or #f if there is no such list. It returns the shortest possible list. > (addup '(2 6 3 4 5) 10)
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### Page1 / 5

Computer Science 61A - Fall 1997 - Harvey - Midterm 2 - CS...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online