Question: 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 representationclass Queue: def __init__(self): self.items = [] def is_empty(self): return self.items ==

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

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!