Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Python coding: Use Binary trees You need to copy into Visual studio the (Binary_search_try.py) example(the Binary_search_try.py) code copy pasted down below: #Define a node class

Python coding: Use Binary trees

You need to copy into Visual studio the (Binary_search_try.py) example(the Binary_search_try.py) code copy pasted down below:

#Define a node class that has left and right sides

class Node:

def __init__(self, Node_value):

self.left = None

self.right = None

self.Node_value = Node_value

#Define a function to insert Node_value in to the tree

def insert(self, Node_value):

# Compare the new value with the parent node

if self.Node_value: # if there is a root node

if Node_value < self.Node_value: # if the value that we need to inser less than root value

if self.left is None: # if no left side node exist

self.left = Node(Node_value) # create a left side node

else: # otherwise (means there is an empty left node)

self.left.insert(Node_value) # put that value in the left node

elif Node_value > self.Node_value: # do the same thing for the right side node if >

if self.right is None:

self.right = Node(Node_value)

else:

self.right.insert(Node_value)

else: # if no root exist

self.Node_value = Node_value # put the value in the root

# Printing the binary tree

def PrintTree(self):

if self.left:

self.left.PrintTree()

print(self.Node_value),

if self.right:

self.right.PrintTree()

# Define main to make a node object and call inser and print functions

def main():

root = Node(25) # creat an object from the node class, I called it root.

root.insert(19)

root.insert(28)

root.insert(13)

root.insert(9)

root.insert(30)

root.insert(17)

root.insert(26)

root.PrintTree()

if __name__ == "__main__":

main()

Python coding

1. Keep all the methods and data without any change.

2. Make a function call it search_bst (element), where element represents an integer number that a user pass to the search_bst method...

3. Make Report whether the element is found on the tree or not.

If the element is found, print the message

("the number : ", element, "is found")

Otherwise, print the message

` ("the number : ", element, "is found").

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

Step: 3

blur-text-image

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

Financial management theory and practice

Authors: Eugene F. Brigham and Michael C. Ehrhardt

12th Edition

978-0030243998, 30243998, 324422695, 978-0324422696

Students also viewed these Programming questions