Answered step by step
Verified Expert Solution
Link Copied!

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

image text in transcribed

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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database And Expert Systems Applications 24th International Conference Dexa 2013 Prague Czech Republic August 2013 Proceedings Part 2 Lncs 8056

Authors: Hendrik Decker ,Lenka Lhotska ,Sebastian Link ,Josef Basl ,A Min Tjoa

2013th Edition

3642401724, 978-3642401725

More Books

Students also viewed these Databases questions

Question

In Problem find f (x). f(x) = xx e

Answered: 1 week ago