Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

class Queue: def __init__(self): self.items = [] def is_empty(self): return self.items == [] def enqueue(self, item): self.items.insert(0,item) def dequeue(self): return self.items.pop() def peek(self): return self.items[-1]

class Queue: def __init__(self): self.items = [] def is_empty(self): return self.items == [] def enqueue(self, item): self.items.insert(0,item) def dequeue(self): return self.items.pop() def peek(self): return self.items[-1] def size(self): return len(self.items)

class BinarySearchTree:

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

def insert(self, new_data): if new_data == self.data: return elif new_data

def get_right(self): return self.right

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

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

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

def get_data(self): return self.data

def create_string(self, spaces): info = ' ' * spaces + str(self.data) if self.left != None: info += ' (l)' + self.left.create_string(spaces+4) if not self.right == None: info += ' (r)' + self.right.create_string(spaces+4) return info

def __str__(self): representation = self.create_string(0) return representationimage text in transcribed

Dectar 9 Not completo Not graded Define the get_breadth_first_traversal(bs_tree) function which takes a binary search tree as a parameter and returns a list of the data values in the tree in breadth-first order (e. as read from top to bottom, left to right). For example, consider the following binary trec: The code below creates this tree, and then calls the get breadth first traversal() function: bs_tree = create_new_bst([55, 24, 8, 51, 25, 72, 781) nodes = get_breadth_first_traversal(bs_tree) print('Breadth-first order:', nodes) The output of the above code is: Breadth-first order: [55, 24, 72, 8, 51, 78, 25] HINT: To perform a breadth-first traversal, you should make use of a Queue (enqueue and dequeue the subtrees as you traverse). You can assume the Quelle class is available (so you can call methods enqueue, dequeue(), is_empty() and size()). You should not include this class in your answer. NOTE: You can assume the Binary Search Tree class is available to you (so you can call methods get_data().get_left() and get_right()). You should not include this class in your answer The header for the function is: def get_breadth_first_traversal(bs_trec): For example: Test Result [1, 2, 3, 4, 5] t = create_new_b5t([1, 2, 3, 4, 5]) print(get_breadth_first_traversal(t)) (3, 1, 5, 2, 4] t = create_new_bst(3, 1, 5, 2, 4]) print(get_breadth_first_traversal(t)) 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_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

Machine Learning And Knowledge Discovery In Databases European Conference Ecml Pkdd 2015 Porto Portugal September 7 11 2015 Proceedings Part 2 Lnai 9285

Authors: Annalisa Appice ,Pedro Pereira Rodrigues ,Vitor Santos Costa ,Joao Gama ,Alipio Jorge ,Carlos Soares

1st Edition

3319235249, 978-3319235240

More Books

Students also viewed these Databases questions

Question

Persuading Your Audience Strategies for

Answered: 1 week ago