Write a main function that creates the nodes

Assignment Help Python Programming
Reference no: EM132863171

Task

Team Members: _

In this practice, we will implement a Binary Search Tree (BST) data structure. You need to implement two classes.

i) The first class is a "node" class that specifies a node in the BST. The node class has three attributes value, left_child and right_child. The init function is given below:

def init (self, key): self.left_child = None self.right_child = None self.value = key

This class also implements the following methods:
a. getValue() that returns the value stored in a node.
b. setValue() that assigns a value to a node. This method takes the value of a node as parameter.
c. getLeft() that returns the left_child of a node.
d. setLeft() assigns a value to the left_child to a node passed as parameter to this method.
e. getRight() that returns the right_child of a node.
f. setRight() assigns a value to the right_child to a node passed as parameter to this method.
ii) The second class is a "BST" class. The BST class contains one attributes called root that holds the pointer to the root node of the Binary Search

Tree. Initially the root points to None. The init below:

def init (self): self.root = None

function is given

This class implements the following methods also:

a. searchNode(self, key), that takes the value of a node to be searched in a BST and returns "Found" if the node is in the list else returns "Not Found".

b. insertNode(self, node), that takes the value of a new node to be inserted in a BST and finds the appropriate position to place this new node.

c. deleteNode(self,key), that takes the value of the key to be removed from the BST and removes the first occurrence of the node with the key value from the BST.

(Hint: Use the algorithm from the lecture slide to implement these methods)

We will use another helper function called inOrder() to print the tree in a particular order (i.e. left-parent-right). This function takes the root of a tree as a parameter.

def inorder(node):
if node: # if the tree is not NULL inorder(node.getleft()) # Traverse the left subtree print(node.getValue(), end=" ") # Print the current node inorder(node.getright()) # Traverse the right subtree

Given the following tree, this function will print the tree as 1 1 2 3 4 5 if called by passing the root of the tree as an argument i.e. inorder(tree.root).

iii) Write a main function that creates the nodes and constructs the tree given above. Then search for keys in the tree e.g. key = 5, as well as keys not in the tree e.g. key = 10. Delete the root from the tree and call the inorder() function to print the tree. The sequence should look like 1 1 3 4 5.

Attachment:- Task.rar

Reference no: EM132863171

Questions Cloud

How are minority women affected by sentencing guidelines : How are minority women affected by sentencing guidelines? Are they more likely to receive a harsher sentence than non-minority women? Why or why not?
Explain the boy behavior according to each of the four crime : Explain the boy's behavior according to each of the four crime causation theories? You must answer all four. Refer to your book, the internet, or other source
Describe the combined dna index system codis : Discuss why it is difficult for law enforcement agencies to work together when they are faced with a case such as that of an active serial killer.
Databases as we collect more contextual : How do you believe smart technologies and the Internet will continue to play and integral role in the use of databases as we collect more contextual,
Write a main function that creates the nodes : Write a main function that creates the nodes and constructs the tree given above. Then search for keys in the tree e.g. key = 5, as well as keys not
Documents that record in writing a team purpose : Charters, mission/ vision statements, memorandum of agreements, constitutions, role and responsibility statements are all examples of documents that record
Describe the killer activities and victim selection : Are there investigative tactics or resources available today that would have been of assistance in the investigation? Describe and critique the investigation
Technological innovation : Choose a technological innovation that has arisen since the Internet Age (2000 - Present) and its artifact or tool.
How the subjugation of gender : How the subjugation of gender (i.e. women and transgenders), race (i.e. black Americans and Indigenous Peoples), and sex (i.e. RSOs and rape victims)

Reviews

Write a Review

Python Programming Questions & Answers

  Write a python program to implement the diff command

Without using the system() function to call any bash commands, write a python program that will implement a simple version of the diff command.

  Write a program for checking a circle

Write a program for checking a circle program must either print "is a circle: YES" or "is a circle: NO", appropriately.

  Prepare a python program

Prepare a Python program which evaluates how many stuck numbers there are in a range of integers. The range will be input as two command-line arguments.

  Python atm program to enter account number

Write a simple Python ATM program. Ask user to enter their account number, and print their initail balance. (Just make one up). Ask them if they wish to make deposit or withdrawal.

  Python function to calculate two roots

Write a Python function main() to calculate two roots. You must input a,b and c from keyboard, and then print two roots. Suppose the discriminant D= b2-4ac is positive.

  Design program that asks user to enter amount in python

IN Python Design a program that asks the user to enter the amount that he or she has budget in a month. A loop should then prompt the user to enter his or her expenses for the month.

  Write python program which imports three dictionaries

Write a Python program called hours.py which imports three dictionaries, and uses the data in them to calculate how many hours each person has spent in the lab.

  Write python program to create factors of numbers

Write down a python program which takes two numbers and creates the factors of both numbers and displays the greatest common factor.

  Email spam filter

Analyze the emails and predict whether the mail is a spam or not a spam - Create a training file and copy the text of several mails and spams in to it And create a test set identical to the training set but with different examples.

  Improve the readability and structural design of the code

Improve the readability and structural design of the code by improving the function names, variables, and loops, as well as whitespace. Move functions close to related functions or blocks of code related to your organised code.

  Create a simple and responsive gui

Please use primarily PHP or Python to solve the exercise and create a simple and responsive GUI, using HTML, CSS and JavaScript.Do not use a database.

  The program is to print the time

The program is to print the time in seconds that the iterative version takes, the time in seconds that the recursive version takes, and the difference between the times.

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd