Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Advances In Databases And Information Systems 23rd European Conference Adbis 2019 Bled Slovenia September 8 11 2019 Proceedings Lncs 11695

Authors: Tatjana Welzer ,Johann Eder ,Vili Podgorelec ,Aida Kamisalic Latific

1st Edition

3030287297, 978-3030287290

More Books

Students also viewed these Databases questions