attached file, you will find a function that creates a binary search tree of a given size and files that will randomly generate keys in the range [1,1000]. The value associated with each key can be passed to the function, default is 1. Complete the program by implementing the necessary code to perform the following tasks: Create a binary search tree of size 20, name it bst Print all keys in bst on a single line to save space Print the mimimum key in bst Print the smallest key larger than 500 in bst (if any) Print all keys in the range [100,300] in bst Print the tree height Import the modules first before doing this. from bst.binary_search_tree import TreeMap
In the attached file, you will find a function that creates a binary search tree of a given size and files that will randomly generate keys in the range [1,1000]. The value associated with each key can be passed to the function, default is 1.
Complete the program by implementing the necessary code to perform the following tasks:
- Create a binary search tree of size 20, name it bst
- Print all keys in bst on a single line to save space
- Print the mimimum key in bst
- Print the smallest key larger than 500 in bst (if any)
- Print all keys in the range [100,300] in bst
- Print the tree height
Import the modules first before doing this.
from bst.binary_search_tree import TreeMap
from AVLTreeMap import AVLTreeMap
import random
def create(size, value = 1):
bst = AVLTreeMap() # or just use AVLTreeMap()
counter = 0
while counter<size:
val = random.randint(1,1000)
if not val in bst.keys():
bst[val] = value
counter +=1
return bst

Trending now
This is a popular solution!
Step by step
Solved in 2 steps









