Question
[Prolog] We represent a node of a binary tree with node(L, R, K) where L is the left subtree, R is the right subtree, and
[Prolog] We represent a node of a binary tree with node(L, R, K) where L is the left subtree, R is the right subtree, and K is the stored integer key. We use nil to represent an empty tree. You are given two binary trees T1 and T2. Imagine that you lay one of them over the other. Some nodes of the two trees overlap while others do not. We want to merges both trees into a new binary tree as it would be seen when laying one tree over the other. If two nodes overlap, the sum of their keys becomes the key of the corresponding node in the new tree. Otherwise, the new node has the same key as the node of the original tree. Write a predicate merge(T1, T2, TM) that is true if TM is the result of merging T1 and T2.
[Prolog] We represent a node of a binary tree with node(L, R, K) where L is the left subtree, R is the right subtree, and K is the stored integer key. We use nil to represent an empty tree. You are given two binary trees T1 and T2. Imagine that you lay one of them over the other. Some nodes of the two trees overlap while others do not. We want to merges both trees into a new binary tree as it would be seen when laying one tree over the other. If two nodes overlap, the sum of their keys becomes the key of the corresponding node in the new tree. Otherwise, the new node has the same key as the node of the original tree. Write a predicate merge(T1, T2, TM) that is true if TM is the result of merging T1 and T2Step 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