1answer.
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]
3 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]3 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 part of a formal email is optional
EleoNora [17]
Contact information will be optional.
6 0
3 years ago
Read 2 more answers
What office application has animations on the home ribbon?
Eva8 [605]
It's Microsoft office power point presentation.
3 0
3 years ago
Read 2 more answers
2. Kabel yang digunakan pada jangan wireline, sebagai
Mumz [18]
It’s b ........................................
7 0
3 years ago
10. Which of these is not an HTTP verb? PUT AJAX GET DELETE
Korolek [52]

Answer:

Brainliest!

Explanation:

The primary or most-commonly-used HTTP verbs (or methods, as they are properly called) are POST, GET, PUT, PATCH, and DELETE. These correspond to create, read, update, and delete (or CRUD) operations, respectively. There are a number of other verbs, too, but are utilized less frequently.

-

restapitutorial

.

com

3 0
3 years ago
Which of the following best describes a toolbar?
nataly862011 [7]
Easy fast access to common apps or programs

3 0
3 years ago
Other questions:
  • An attribute whose value uniquely identifies an object is called a(n) _______.​
    15·1 answer
  • How many questions must you answer in Brainly to be able to message people?
    6·2 answers
  • How long did it take Linkedln to reach 1 million users?
    5·2 answers
  • Two technicians are discussing the voltage measurements taken on the circuit below: V1 = 12Volts; V2 = 12Volts; V3 = 0Volts; V4
    11·1 answer
  • python Consider this data sequence: "3 11 5 5 5 2 4 6 6 7 3 -8". Any value that is the same as the immediately preceding value i
    7·1 answer
  • You attempt to telnet to system 192.168.1.240. You receive the following message: "Connecting To 192.168.1.240...Could not open
    5·1 answer
  • Why was the tesla model s help change the was we see EV
    12·1 answer
  • The __________ statement allows you to check for
    7·1 answer
  • What is the most popular game design engine today
    7·2 answers
  • write a recursive bool valued function containsvowel that accepts a string and returns true if the string contains a vowel
    6·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!