Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

(15 pts) Consider binary trees where each node contains an integer. Here is an example of a binary tree. 3 6 5 5 7 8

image text in transcribed
image text in transcribed
(15 pts) Consider binary trees where each node contains an integer. Here is an example of a binary tree. 3 6 5 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 tree t 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; 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 treet and output is the right subtree of the root of t; function empty: its input is any tree t and output is true if treet is empty (i.e., there are no nodes) and false otherwise; function set: its input is a treet 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. DO NOT write your answer in the space below, but write it on your physical paper (or the device you use to manually compose your answer)

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

Database Marketing The Ultimate Marketing Tool

Authors: Edward L. Nash

1st Edition

0070460639, 978-0070460638

More Books

Students also viewed these Databases questions

Question

2. What are your challenges in the creative process?

Answered: 1 week ago