Question: Language = Scheme Define a procedure called (treemerge t1 t2) that takes two trees (arbitrarily nested lists) and returns the result of merging the two
Language = Scheme
Define a procedure called (treemerge t1 t2) that takes two trees (arbitrarily nested lists) and returns the result of merging the two trees using the following guidelines:
- Merging two trees is done by recursing through their structure and multiplying their subtrees
The root of t1 is merged with the root of t2
The first child is merged with the first child
Second with second... etc, etc, etc, ...
- Merging two leaf nodes is done by multiplying their values (you may assume they are numbers).
- Merging a leaf node with a subtree is done by scaling the subtree by the value of the leaf.
- Merging a subtree with an empty tree, is simply the non-empty subtree.
E.g.: (treemerge '(2 (2 3) (4 5 (5 6 7))) '((5 (4 3) (2 1)) 6 (7 8))) ? ((10 (8 6) (4 2)) (12 18) (28 40 (5 6 7)))
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
