Question: Extend your python program below to include the recursive methods, as described in part A , B ad C. class BST: def __init__(self,data): self.root =

Extend your python program below to include the recursive methods, as described in part A , B ad C.

class BST:

def __init__(self,data):

self.root = data

self.left = None

self.right = None

def insert(self,data):

if self.root == None:

self.root = BST(data)

elif data > self.root:

if self.right == None:

self.right = BST(data)

else:

self.right.insert(data)

elif data < self.root:

if self.left == None:

self.left = BST(data)

else:

self.left.insert(data)

def inordertraversal(self):

if self.left != None:

self.left.inordertraversal()

print (self.root),

if self.right != None:

self.right.inordertraversal()

t = BST(9)

t.insert(8)

t.insert(3)

t.insert(6)

t.insert(12)

t.insert(10)

t.insert(11)

t.inordertraversal()

(a) numberOfNodes Accepts a BST node r and returns an integer value of the

number of nodes in the BST whose root is r.

(b) treeHeight Accepts a BST node r and returns and integer value of the height

of the BST whose root is r.

(c) numberOfLeaves Accepts a BST node r and returns an integer value of the

number of leaves in the BST whose root is r.

Comment: You may choose to submit pseudocode only for Question 9. Include it

along with your Part A. Each algorithm will require very few lines of code. Do not

use extra local (or global) variables, they are unnecessary. Think: \if at the base

case, return base case solution" else eturn something involving a recursive call".

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!