Answered step by step
Verified Expert Solution
Question
1 Approved Answer
(define (make-tree value left right) (list value left right)) (define (value tree) (car tree)) (define (left tree) (cadr tree)) (define (right tree) (caddr tree)) 1.
(define (make-tree value left right) (list value left right)) (define (value tree) (car tree)) (define (left tree) (cadr tree)) (define (right tree) (caddr tree)) 1. This problem concerns ways to represent arithmetic expressions using trees. For this purpose, we will consider 4 arithmetic operations: + and *, both of which take two arguments, and - and Va, both of which take one argument. (As an example of how these one-argument operators work, the result of applying the operator - to the number 5 is the number -5; likewise, the result of applying the 1/o operator to the number 5 is the number 1/5.) An arithmetic parse tree is a special tree in which every node has zero, one, or two children and: . each leaf contains a numeric value, and every internal node with exactly two children contains one of the two arithmetic operators+ or * every internal node with exactly one child contains one of the two arithmetic operators or Vo. (You may assume, for this problem and the next, that when a node has a single child, this child appears as the left subtree.) If T is an arithmetic parse tree, we associate a value with T (which we call value(T)) by the fol- lowing recursive rule: if T has a single (leaf) node, value(T) is equal to the numeric value of the node, if T has two subtrees, L and R, and its root node contains the operator +, then value(T) value(L) +value(R) if T has two subtrees, L and R, and its root node contains the operator *, then value(T) = value(L) *value(R), if T has one subtree, S, and its root node contains the operator-, then value (T)value(S), if T has one subtree, S, and its root node contains the operator , then value(T)-1 / value(s). (define (make-tree value left right) (list value left right)) (define (value tree) (car tree)) (define (left tree) (cadr tree)) (define (right tree) (caddr tree)) 1. This problem concerns ways to represent arithmetic expressions using trees. For this purpose, we will consider 4 arithmetic operations: + and *, both of which take two arguments, and - and Va, both of which take one argument. (As an example of how these one-argument operators work, the result of applying the operator - to the number 5 is the number -5; likewise, the result of applying the 1/o operator to the number 5 is the number 1/5.) An arithmetic parse tree is a special tree in which every node has zero, one, or two children and: . each leaf contains a numeric value, and every internal node with exactly two children contains one of the two arithmetic operators+ or * every internal node with exactly one child contains one of the two arithmetic operators or Vo. (You may assume, for this problem and the next, that when a node has a single child, this child appears as the left subtree.) If T is an arithmetic parse tree, we associate a value with T (which we call value(T)) by the fol- lowing recursive rule: if T has a single (leaf) node, value(T) is equal to the numeric value of the node, if T has two subtrees, L and R, and its root node contains the operator +, then value(T) value(L) +value(R) if T has two subtrees, L and R, and its root node contains the operator *, then value(T) = value(L) *value(R), if T has one subtree, S, and its root node contains the operator-, then value (T)value(S), if T has one subtree, S, and its root node contains the operator , then value(T)-1 / value(s)
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started