Question
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
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