answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
ivann1987 [24]
2 years ago
13

Write the recursive function max_depth; it is passed a binary (any binary tree, not necessarily a binary search tree) and a valu

e as arguments. It returns the maxim depth in the tree at which that value occurs. Note the root is depth 0; its children are at depth 1; its grandchildren are at depth 2, etc. Generally, if a parent is at depth d, its children are at depth d 1. In the binary tree below, max_depth(tree,1) returns 1, max_depth (tree,2) returns 3, max_depth (tree,3) returns 2. The value may appear at many depths. ..1

Computers and Technology
1 answer:
OleMash [197]2 years ago
8 0

Answer:

A python code was used in writing of the recursive function max_depth; and passed a binary (any binary tree, not necessarily a binary search tree) and a value as arguments.

Explanation:

Solution

To solve this given question we make use of Python programming language.

Thus

THE CODE:

class BinaryTreeNode:

def __init__(self, value, left=None, right=None):

self.value = value

self.left = left

self.right = right

# recursive max_depth function implementation

def max_depth(tree, value):

if tree == None:

return -1

# recursive calls to this function

leftDepth = max_depth(tree.left, value)

rightDepth = max_depth(tree.right, value)

# return the maximum depth

if tree.value == value or leftDepth > -1 or rightDepth > -1:

return 1 + max(leftDepth, rightDepth)

else:

return max(leftDepth, rightDepth)

btn1 = BinaryTreeNode(2)

btn2 = BinaryTreeNode(3, None, btn1)

btn3 = BinaryTreeNode(3)

btn4 = BinaryTreeNode(3)

btn5 = BinaryTreeNode(2, btn2, btn3)

btn6 = BinaryTreeNode(1, btn4)

tree = BinaryTreeNode(3, btn5, btn6)

print('max_depth(tree, 1):',max_depth(tree, 1))

print('max_depth(tree, 2):',max_depth(tree, 2))

print('max_depth(tree, 3):',max_depth(tree, 3))

Note: Kindly find an attached copy of the Implementation of max_depth() function, Code to test the max_depth() function and the sample output below.

You might be interested in
Which act was used to penalize Sara? Sara was found to be in possession of a controlled substance for which she had no justifica
andre [41]
<span>si la sustancia es droga, cárcel</span>
6 0
2 years ago
Phillip is a wellness counselor. He has created a newsletter as a service for his clients. He needs to decide upon a method to d
Alexus [3.1K]
The best technology that Philip could use is the Email Newsletters.  <span> Sent on a regular basis, a content-based email newsletter not only helps you stay on top, but also showcases your updates concerning wellness,  C</span>reate a newsletter that will engage your users.  <span>Ensure that each content is educational, informative, and short but clear. </span>
3 0
2 years ago
In the graph shown here, by what percentage are the number of people in computer occupations in general projected to increase?
SOVA2 [1]

Answer:

12% or 21%

Explanation:

not really sure

8 0
2 years ago
Read 2 more answers
Type the correct answer in the box. Spell all words correctly.
kvasek [131]

Answer:

Presentations?

Explanation:

6 0
2 years ago
What is ODBC? How is it related to SQL/CLI? 10.2. What is JDBC? Is it an example of embedded SQL or of using function calls? 10.
tamaranim1 [39]

Answer:hhhhhhhhh

Explanation:

5 0
2 years ago
Other questions:
  • When a machine on the public network wants to reach the server at 172.30.0.10, which ip will it use?
    6·2 answers
  • Modern operating systems decouple a process address space from the machine’s physical memory. List two advantages of this design
    15·1 answer
  • Jennifer has written a short story for children. What should be her last step before she submits the story for publication?
    11·1 answer
  • Information systems cannot solve some business problems. Give three examples and explain why technology cannot help.
    11·1 answer
  • Three variables , x, y and z, supposedly hold strings of digits, suitable for converting to integers. Write code that converts t
    9·2 answers
  • They predicted another cold day in Seattle. They predicted another windy day in Seattle. Combine the sentences into one sentence
    8·1 answer
  • How do many corporations most likely manage the health and safety of their employees and the workplace?
    13·1 answer
  • A collection of technologies that allow publishing of search results in a format suitable for syndication and aggregation. It is
    5·1 answer
  • Write a method so that the main() code below can be replaced by simpler code that calls method calcMilesTraveled(). Original mai
    11·1 answer
  • You work at a computer repair store. A customer is having trouble with their hard drives. The computer is not recognizing all th
    7·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!