Answered step by step
Verified Expert Solution
Question
1 Approved Answer
In Python, Link to Class: https://pastebin.com/42w6Tv0v Define a function called print insert position0 which takes a binary search tree as input, as well as a
In Python,
Link to Class: https://pastebin.com/42w6Tv0v
Define a function called print insert position0 which takes a binary search tree as input, as well as a value to be inserted into the tree. The function should not modify the tree at all -instead, it should simply print the position at which value would be inserted into the tree. This involves printing the node under which the value would be inserted, after either To the left of" or "To the right of If the data value to be inserted already exists in the tree, then the function should print "Duplicate The example code below makes use of the Binary Tree class: Class BinaryTree: def init_(self, data) self.data data self.left None self.right - None def insert left(self, new_data): if self.left None: self.left BinaryTree(new data) else: t BinaryTree(new_data) t.left-self.left self.leftt def insert right(self, new data): if self.rightNone: self.right BinaryTree(new_data) else: tBinaryTree(new_data) t.right-self.right self.right -t def get_left(self): return self.left 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 getdata self): return self.data For example: Test Result a-BinaryTree(100) print insert_positionCa, 29) To the left of 100 a -BinaryTree(50) a.insert_left (10) a.insert_left(20) a.insert left(30) a.insert.left(40) To the left of 10 print insert positionCa, 5)Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started