# a7 - CS 135 Fall 2008 Byron Weber Becker Ian Goldberg Brad...

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

Byron Weber Becker, Ian Goldberg, Brad Lushman, Daniel Roche, Troy Vasiga Assignment 7 Due Wednesday, November 5, 10:30am Files to submit: cross.ss , evaluate.ss , bst.ss , is-bst.ss , decode.ss and (for the bonus) treesfromto.ss . Language level : Intermediate Student Extra practice exercises : (Not to be submitted) HtDP 16.1.1, 16.2.1, 16.3.2, 16.3.4, 17.2.2 Note : The Intermediate Student language allows you to create and use local de±nitions for in- termediate computations in your functions. While none of the questions below explicitly ask you to create local de±nitions, you are expected to exercise good judgement and use local de±nitions in your solutions where appropriate. Note : Appropriate uses of the function append are permitted on this assignment. 1. HtDP, exercise 17.1.2. Place your solution in the ±le cross.ss . 2. Place your solution for this question in the ±le evaluate.ss . Your course notes contain a data de±nition for arithmetic expressions (aexps). Consider the following slight modi±cation of that data de±nition: an arithmetic expression (aexp) is a number or a symbol or ( make-ae op ael ), where op is a symbol and ael is a ( listof aexp ). By allowing aexps to be symbols, we can construct arithmetic expression lists that contain constants. For example: ( make-ae + ( list 3 x ( make-ae * ( list y y )))). Write the function evaluate to compute the value of an arithmetic expression. The function con- sumes an arithmetic expression and an association list, and produces the value of the expression. The association list (from symbols to numbers) will act as a dictionary, indicating the numeric value of each constant. Example: ( evaluate ( make-ae + ( list x4 )) ’(( x5 )( y7 ))) should yield the value 9. If you encounter a constant in the arithmetic expression that is not present in the association list, then evaluate should evaluate the expresson ( error evaluate ”Undefned con- stant.” ). You may also assume that the only valid operators (the symbol op in the data de±nition) in an aexp are ’ + and ’ * . 3. Place your solution for this question in the ±le bst.ss . For this question, you should use the node structure de±ned in Module 6. De±ne a list all-4-trees that contains all possible binary search trees that contain all of the numbers 1, 2, 3, and 4 exactly once (use ”” for the value ±eld). To get you started, the solution for all binary search trees on 1 and 2 would be as follows: ( defne all-2-trees ( list ( make-node 1 ”” empty ( make-node 2 ”” empty empty )) ( make-node 2 ”” ( make-node 1 ”” empty empty ) empty ) )) The order in which your trees occur in the list is not important. CS 135 – Fall 2008

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

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

## This note was uploaded on 01/10/2011 for the course CSC 135 taught by Professor Steveeangels during the Fall '08 term at University of Toronto.

### Page1 / 4

a7 - CS 135 Fall 2008 Byron Weber Becker Ian Goldberg Brad...

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

View Full Document
Ask a homework question - tutors are online