Question: Needing help Consider binary trees where each node contains an integer. Here is an example of a binary tree. 4 6 5 7 8 The

Needing help

Needing help Consider binary trees where each node contains an integer. Here

Consider binary trees where each node contains an integer. Here is an example of a binary tree. 4 6 5 7 8 The root node of the whole tree above is the node at the root with integer 3. The left subtree of the root node 3 is the tree with root node 4 that has child node 5. The right subtree of the root node 3 is the tree with node (with integer 6) and two children with integers of 7 and 8. Write an algorithm such that its input is a binary treet and a number x, it has no output, and it has a side effect of setting the integer at every node of t to be x. Use the problem decomposition method to design the algorithm. You are not allowed to use loops. Make the problem decomposition and their decomposability condition explicit in your algorithm. Your algorithm must follow the format discussed in class. In your algorithm, no other functions are allowed except the following: function Ichild its input is any treet and output is the left subtree of the root of t, function rchild its input is any tree t and output is the right subtree of the root of t. function empty: its input is any tree t and output is true if tree t is empty (i.e. there are no nodes) and false otherwise; function set its input is a tree t and a number x, it has no output, and its side effect is to set the integer at the root node of t to be x. Hint: a tree can usually be decomposed as three parts: its root, its left tree and its right tree

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!