Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

EXISTING CODE class BinaryTree: def __init__(self, data, left=None, right=None): self.data = data self.left = left self.right = right def insert_left(self, new_data): if self.left == None:

image text in transcribed

EXISTING CODE

class BinaryTree: def __init__(self, data, left=None, right=None): self.data = data self.left = left self.right = right

def insert_left(self, new_data): if self.left == None: self.left = BinaryTree(new_data) else: t = BinaryTree(new_data, left=self.left) self.left = t

def insert_right(self, new_data): if self.right == None: self.right = BinaryTree(new_data) else: t = BinaryTree(new_data, right=self.right) self.right = t

def get_left(self): return self.left

def get_right(self): return self.right

def set_data(self, data): self.data = data

def get_data(self): return self.data

def set_left(self, left): self.left = left

def set_right(self, right): self.right = right

Define a function named is_full (my_tree) which takes a binary tree as a parameter and returns True if the given tree is full, and False otherwise. A full binary tree is defined as a binary tree in which all nodes have either zero or two child nodes. Conversely, there is no node with only one child in a ful binary tree. For example, consider the following binary tree: 41 The result is False (node 29 has only one child). Notes: - You cannot reuse the is_full_node() method developed in Q4 as you need to differentiate between the case where a node has no child and the case where a node has 2 children. - A BinaryTree implementation is provided to you as part of this exercise - you should not define your own BinaryTree class. Instead, your code can make use of any of the BinaryTree ADT data fields or methods. For example: Answer: (penalty regime: 0,0,5,10,15,20,25,30,35,40,45,50% )

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

Step: 3

blur-text-image

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 Concepts International Edition

Authors: David M. Kroenke

6th Edition International Edition

0133098222, 978-0133098228

More Books

Students also viewed these Databases questions