Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Consider the following representation of binary trees: an empty tree is represented as an empty tuple ({} in Picat and () in Haskell), and a

Consider the following representation of binary trees: an empty tree is represented as an empty tuple ({} in Picat and () in Haskell), and a binary tree node is represented as a three-element tuple, where the rst element is the node value, the second element is the left child, and the third element is the right child. Write the following functions on binary trees. 1. member(x,btree): This function checks if x occurs in btree. The binary tree btree is not necessarily a binary search tree. 2. one child node values(btree): This function takes a binary tree and returns a list of values of the nodes in the tree that have exactly one child. The order of the values in the list is not important. 3. equal(t1,t2): tests if tree t1 and tree t2 are equal. Two binary trees are equal if (1) both are empty; or (2) the roots have the same value, the two left subtrees are equal, and the two right subtrees are equal. 4. shallowest leaf(btree) (extra 5 points): This function returns the values in a shallowest leaf node in btree. If there are multiple such leaves, then the function returns the left-most one.

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

Step: 3

blur-text-image

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

Ai And The Lottery Defying Odds With Intelligent Prediction

Authors: Gary Covella Ph D

1st Edition

B0CND1ZB98, 979-8223302568

More Books

Students also viewed these Databases questions

Question

8. Explain the difference between translation and interpretation.

Answered: 1 week ago

Question

10. Discuss the complexities of language policies.

Answered: 1 week ago

Question

1. Understand how verbal and nonverbal communication differ.

Answered: 1 week ago