Python code:   ############################## class Node:     def __init__(self,value):         self.left = None         self.right = None         self.val = value ############################### class BinarySearchTree:     def __init__(self):         self.root = None def print_tree(node):      if node == None:         return     print_tree(node.left)     print_tree(node.right)      print(node.val) ################################################# # Task 1: get_nodes_in_range function #################################################   def get_nodes_in_range(node,min,max):      #      # your code goes here      #      pass # fix this if __name__ == '__main__':     BST = BinarySearchTree()     BST.root = Node(10)     BST.root.left = Node(5)     BST.root.right = Node(15)     BST.root.left.left = Node(2)     BST.root.left.right = Node(8)     BST.root.right.left = Node(12)     BST.root.right.right = Node(20)     BST.root.right.right.right = Node(25)       print(get_nodes_in_range(BST.root, 6, 20))

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

Python code:

 

##############################
class Node:
    def __init__(self,value):
        self.left = None
        self.right = None
        self.val = value

###############################
class BinarySearchTree:
    def __init__(self):
        self.root = None

def print_tree(node): 
    if node == None:
        return
    print_tree(node.left)
    print_tree(node.right) 
    print(node.val)


#################################################
# Task 1: get_nodes_in_range function
#################################################  
def get_nodes_in_range(node,min,max):
     #
     # your code goes here
     #
     pass # fix this


if __name__ == '__main__':
    BST = BinarySearchTree()
    BST.root = Node(10)
    BST.root.left = Node(5)
    BST.root.right = Node(15)
    BST.root.left.left = Node(2)
    BST.root.left.right = Node(8)
    BST.root.right.left = Node(12)
    BST.root.right.right = Node(20)
    BST.root.right.right.right = Node(25)
 
    print(get_nodes_in_range(BST.root, 6, 20))

In this lab you are provided with a pre-populated Binary Search Tree and asked to implement the function get_nodes_in_range (node,
min, max) which returns a list (Python built-in list) of all the values in nodes in the tree which are within the range (inclusive of the min and
max).
As an example, for the following BST:
BST = BinarySearchTree ()
BST.root = Node (10)
BST.root.left = Node (5)
BST.root.right = Node (15)
BST.root.left.left = Node (2)
BST.root.left.right = Node (8)
the expected output for get_nodes_in_range (BST.root, 6, 20) is a list containing the following values:
[8, 15, 10]
NOTE: the order of the nodes in the list doesn't matter. The tests will check that the list returned by your function contains the same values
Transcribed Image Text:In this lab you are provided with a pre-populated Binary Search Tree and asked to implement the function get_nodes_in_range (node, min, max) which returns a list (Python built-in list) of all the values in nodes in the tree which are within the range (inclusive of the min and max). As an example, for the following BST: BST = BinarySearchTree () BST.root = Node (10) BST.root.left = Node (5) BST.root.right = Node (15) BST.root.left.left = Node (2) BST.root.left.right = Node (8) the expected output for get_nodes_in_range (BST.root, 6, 20) is a list containing the following values: [8, 15, 10] NOTE: the order of the nodes in the list doesn't matter. The tests will check that the list returned by your function contains the same values
Expert Solution
steps

Step by step

Solved in 3 steps with 1 images

Blurred answer
Knowledge Booster
Generic Type
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education