Define a function called get_list_by_level(bst) which takes a binary search tree as a parameter. The function should ret
Posted: Fri May 20, 2022 12:56 pm
Define a function called get_list_by_level(bst) which takes a binary search tree as a parameter. The function should return a Python list containing values in the level-order traversal of the parameter binary search tree (i.e. the function visits every node on a level before going to a lower level). For example, the following binary tree: 64 1 / / 84 66 11 / 32 40 / 20 55 produces: [64, 84, 66, 32, 40, 20, 55] You may want to use a Queue data structure, where the root node is initially put into the queue, and then the queue is processed as follows: • While the queue is not empty o Remove the front element of the queue o Append the value into the result list o Enqueue the left child into the queue if it is not None • Enqueue the right child into the queue if it is not None Note: You can assume that the parameter binary search tree is not empty. IMPORTANT: For this exercise, you will be defining a function which USES the BinarySearch Tree ADT and the Queue ADT. Both implementations are provided to you as part of this exercise - you should not define them in your answer. Instead, your code can make use of any of the BinarySearchTree/Queue ADT fields and methods. For example: Test Result print(get_list_by_level(tree1)) [7, 2, 9, 1, 5]