SlideShare une entreprise Scribd logo
1  sur  5
Télécharger pour lire hors ligne
PLEASE ANSWER IN PYTHON
In this assignment you will be adding to the classes Node and Tree that we developed in Binary
Search Tree
Lecture and testing them. There are several short methods that you will have to write.
Write a method range() that returns the range of values stored in a binary search tree of integers.
The
range of values equals the maximum value in the binary search tree minus the minimum value.
If
there is one value in the tree the range is 0. If the tree is empty the range is undefined.
def range (self):
Write a method get level() that takes as input the level and returns a list of all the nodes at that
level
from left to right. If that level does not exist for that binary search tree return an empty list . Use
the
convention that the root is at level 0.
def get level (self, level):
Write a method left side view() when given the root of a binary tree, imagine yourself standing
on the
left side of it, return the values of the nodes you can see ordered from top to bottom.
def left side view (self):
Write a method sum leaf nodes() that returns the sum of the value of all leaves. Recall that a
leaf node
does not have any children.
def sum leaf node (self):
In this assignment you will be writing helper methods for the Tree class that we developed and
test them.
The following is the outline of the code that you will be submitting. You may include the other
functions
that we developed for completeness.
Input:
50 30 70 10 40 60 80 7 25 38 47 58 65 77 96
50 30 70 10 40 60 80 7 25 38 47 58 65 77 96
58 77 65 30 38 50 7 25 47 96 80 10 60 70 40
Starter Code
import sys
class Node (object):
# constructor
def __init__(self, data):
self.data = data
self.lChild = None
self.rChild = None
def print_node(self, level=0):
if self.lChild != None:
self.lChild.print_node(level + 1)
print(' ' * 3 * level + '->', self.data)
if self.rChild != None:
self.rChild.print_node(level + 1)
def get_height(self):
if self.lChild != None and self.rChild != None:
return 1 + max(self.lChild.get_height(), self.rChild.get_height())
elif self.lChild != None:
return 1 + self.lChild.get_height()
elif self.rChild != None:
return 1 + self.rChild.get_height()
else:
return 1
class Tree(object):
# constructor
def __init__(self):
self.root = None
def print(self, level):
self.root.print_node(level)
def get_height(self):
return self.root.get_height()
# Inserts data into Binary Search Tree and creates a valid BST
def insert(self, data):
new_node = Node(data)
if self.root == None:
self.root = new_node
return
else:
parent = self.root
curr = self.root
# finds location to insert new node
while curr != None:
parent = curr
if data < curr.data:
curr = curr.lChild
else:
curr = curr.rChild
# inserts new node based on comparision to parent node
if data < parent.data:
parent.lChild = new_node
else:
parent.rChild = new_node
return
# Returns the range of values stored in a binary search tree of integers.
# The range of values equals the maximum value in the binary search tree minus
the minimum value.
# If there is one value in the tree the range is 0. If the tree is empty the
range is undefined.
def range(self):
# Returns a list of nodes at a given level from left to right
def get_level(self, level):
# Returns the list of the node that you see from left side
# The order of the output should be from top to down
def left_side_view(self):
# returns the sum of the value of all leaves.
# a leaf node does not have any children.
def sum_leaf_nodes(self):
def make_tree(data):
tree = Tree()
for d in data:
tree.insert(d)
return tree
# Develop your own main function or test cases to be able to develop.
# Our tests on the Gradescop will import your classes and call the methods.
def main():
# Create three trees - two are the same and the third is different
line = sys.stdin.readline()
line = line.strip()
line = line.split()
tree1_input = list(map(int, line)) # converts elements into ints
t1 = make_tree(tree1_input)
t1.print(t1.get_height())
print("Tree range is: ", t1.range())
print("Tree left side view is: ", t1.left_side_view())
print("Sum of leaf nodes is: ", t1.sum_leaf_nodes())
print("##########################")
# Another Tree for test.
line = sys.stdin.readline()
line = line.strip()
line = line.split()
tree2_input = list(map(int, line)) # converts elements into ints
t2 = make_tree(tree2_input)
t2.print(t2.get_height())
print("Tree range is: ", t2.range())
print("Tree left side view is: ", t2.left_side_view())
print("Sum of leaf nodes is: ", t2.sum_leaf_nodes())
print("##########################")
# Another Tree
line = sys.stdin.readline()
line = line.strip()
line = line.split()
tree3_input = list(map(int, line)) # converts elements into ints
t3 = make_tree(tree3_input)
t3.print(t3.get_height())
print("Tree range is: ", t3.range())
print("Tree left side view is: ", t3.left_side_view())
print("Sum of leaf nodes is: ", t3.sum_leaf_nodes())
print("##########################")
if __name__ == "__main__":
main()

Contenu connexe

Similaire à PLEASE ANSWER IN PYTHONIn this assignment you will be adding to th.pdf

Please help me fix this code! will upvote. The code needs to produce .pdf
Please help me fix this code! will upvote.  The code needs to produce .pdfPlease help me fix this code! will upvote.  The code needs to produce .pdf
Please help me fix this code! will upvote. The code needs to produce .pdfclimatecontrolsv
 
In this assignment- you will work with graphs- Begin with the -useGrap.pdf
In this assignment- you will work with graphs- Begin with the -useGrap.pdfIn this assignment- you will work with graphs- Begin with the -useGrap.pdf
In this assignment- you will work with graphs- Begin with the -useGrap.pdfsidkucheria
 
Need done for Date Structures please! 4-18 LAB- Sorted number list imp.pdf
Need done for Date Structures please! 4-18 LAB- Sorted number list imp.pdfNeed done for Date Structures please! 4-18 LAB- Sorted number list imp.pdf
Need done for Date Structures please! 4-18 LAB- Sorted number list imp.pdfinfo114
 
Python Workshop - Learn Python the Hard Way
Python Workshop - Learn Python the Hard WayPython Workshop - Learn Python the Hard Way
Python Workshop - Learn Python the Hard WayUtkarsh Sengar
 
Data Wrangling with Pandas
Data Wrangling with PandasData Wrangling with Pandas
Data Wrangling with PandasLuis Carrasco
 
Pandas cheat sheet_data science
Pandas cheat sheet_data sciencePandas cheat sheet_data science
Pandas cheat sheet_data scienceSubrata Shaw
 
Pandas Cheat Sheet
Pandas Cheat SheetPandas Cheat Sheet
Pandas Cheat SheetACASH1011
 
python3 HashTableSolutionmain.pyfrom ChainingHashTable impor.pdf
python3 HashTableSolutionmain.pyfrom ChainingHashTable impor.pdfpython3 HashTableSolutionmain.pyfrom ChainingHashTable impor.pdf
python3 HashTableSolutionmain.pyfrom ChainingHashTable impor.pdfinfo706022
 
Odoo - From v7 to v8: the new api
Odoo - From v7 to v8: the new apiOdoo - From v7 to v8: the new api
Odoo - From v7 to v8: the new apiOdoo
 
Python Spell Checker
Python Spell CheckerPython Spell Checker
Python Spell CheckerAmr Alarabi
 
Python-for-Data-Analysis.pptx
Python-for-Data-Analysis.pptxPython-for-Data-Analysis.pptx
Python-for-Data-Analysis.pptxParveenShaik21
 
A limited guide to intermediate and advanced Ruby
A limited guide to intermediate and advanced RubyA limited guide to intermediate and advanced Ruby
A limited guide to intermediate and advanced RubyVysakh Sreenivasan
 
Please help this code is supposed to evaluate current node state and i.pdf
Please help this code is supposed to evaluate current node state and i.pdfPlease help this code is supposed to evaluate current node state and i.pdf
Please help this code is supposed to evaluate current node state and i.pdfclimatecontrolsv
 

Similaire à PLEASE ANSWER IN PYTHONIn this assignment you will be adding to th.pdf (20)

Please help me fix this code! will upvote. The code needs to produce .pdf
Please help me fix this code! will upvote.  The code needs to produce .pdfPlease help me fix this code! will upvote.  The code needs to produce .pdf
Please help me fix this code! will upvote. The code needs to produce .pdf
 
In this assignment- you will work with graphs- Begin with the -useGrap.pdf
In this assignment- you will work with graphs- Begin with the -useGrap.pdfIn this assignment- you will work with graphs- Begin with the -useGrap.pdf
In this assignment- you will work with graphs- Begin with the -useGrap.pdf
 
Need done for Date Structures please! 4-18 LAB- Sorted number list imp.pdf
Need done for Date Structures please! 4-18 LAB- Sorted number list imp.pdfNeed done for Date Structures please! 4-18 LAB- Sorted number list imp.pdf
Need done for Date Structures please! 4-18 LAB- Sorted number list imp.pdf
 
Python Workshop - Learn Python the Hard Way
Python Workshop - Learn Python the Hard WayPython Workshop - Learn Python the Hard Way
Python Workshop - Learn Python the Hard Way
 
Data Wrangling with Pandas
Data Wrangling with PandasData Wrangling with Pandas
Data Wrangling with Pandas
 
Pandas cheat sheet_data science
Pandas cheat sheet_data sciencePandas cheat sheet_data science
Pandas cheat sheet_data science
 
Pandas Cheat Sheet
Pandas Cheat SheetPandas Cheat Sheet
Pandas Cheat Sheet
 
Pandas cheat sheet
Pandas cheat sheetPandas cheat sheet
Pandas cheat sheet
 
python3 HashTableSolutionmain.pyfrom ChainingHashTable impor.pdf
python3 HashTableSolutionmain.pyfrom ChainingHashTable impor.pdfpython3 HashTableSolutionmain.pyfrom ChainingHashTable impor.pdf
python3 HashTableSolutionmain.pyfrom ChainingHashTable impor.pdf
 
interenship.pptx
interenship.pptxinterenship.pptx
interenship.pptx
 
Odoo from 7.0 to 8.0 API
Odoo from 7.0 to 8.0 APIOdoo from 7.0 to 8.0 API
Odoo from 7.0 to 8.0 API
 
Odoo - From v7 to v8: the new api
Odoo - From v7 to v8: the new apiOdoo - From v7 to v8: the new api
Odoo - From v7 to v8: the new api
 
C Exam Help
C Exam Help C Exam Help
C Exam Help
 
Python Spell Checker
Python Spell CheckerPython Spell Checker
Python Spell Checker
 
Programs.doc
Programs.docPrograms.doc
Programs.doc
 
AI-Programs.pdf
AI-Programs.pdfAI-Programs.pdf
AI-Programs.pdf
 
Python-for-Data-Analysis.pptx
Python-for-Data-Analysis.pptxPython-for-Data-Analysis.pptx
Python-for-Data-Analysis.pptx
 
A limited guide to intermediate and advanced Ruby
A limited guide to intermediate and advanced RubyA limited guide to intermediate and advanced Ruby
A limited guide to intermediate and advanced Ruby
 
Please help this code is supposed to evaluate current node state and i.pdf
Please help this code is supposed to evaluate current node state and i.pdfPlease help this code is supposed to evaluate current node state and i.pdf
Please help this code is supposed to evaluate current node state and i.pdf
 
Lecture 9.pptx
Lecture 9.pptxLecture 9.pptx
Lecture 9.pptx
 

Plus de alicesilverblr

Part B Vulnerability Management Plan To prepare a vulnerability.pdf
Part B Vulnerability Management Plan To prepare a vulnerability.pdfPart B Vulnerability Management Plan To prepare a vulnerability.pdf
Part B Vulnerability Management Plan To prepare a vulnerability.pdfalicesilverblr
 
Part 1 � 10 marksAster Turane Computers uses a perpetual accountin.pdf
Part 1 � 10 marksAster Turane Computers uses a perpetual accountin.pdfPart 1 � 10 marksAster Turane Computers uses a perpetual accountin.pdf
Part 1 � 10 marksAster Turane Computers uses a perpetual accountin.pdfalicesilverblr
 
Part 1 Refer to pages 92-100 in your text as you answer these quest.pdf
Part 1 Refer to pages 92-100 in your text as you answer these quest.pdfPart 1 Refer to pages 92-100 in your text as you answer these quest.pdf
Part 1 Refer to pages 92-100 in your text as you answer these quest.pdfalicesilverblr
 
Para arz B�y�k Buhran srasnda d�t� ��nk� __________. Yant se�enekl.pdf
Para arz B�y�k Buhran srasnda d�t� ��nk� __________. Yant se�enekl.pdfPara arz B�y�k Buhran srasnda d�t� ��nk� __________. Yant se�enekl.pdf
Para arz B�y�k Buhran srasnda d�t� ��nk� __________. Yant se�enekl.pdfalicesilverblr
 
Pandas is a Python library used for working with data sets. It has f.pdf
Pandas is a Python library used for working with data sets. It has f.pdfPandas is a Python library used for working with data sets. It has f.pdf
Pandas is a Python library used for working with data sets. It has f.pdfalicesilverblr
 
page 6-7 Fraud (previously referred to as irregularities) -Inten.pdf
page 6-7 Fraud (previously referred to as irregularities) -Inten.pdfpage 6-7 Fraud (previously referred to as irregularities) -Inten.pdf
page 6-7 Fraud (previously referred to as irregularities) -Inten.pdfalicesilverblr
 
page 9 STAFF DISCUSSION OF THE RISK OF MATERIAL MISSTATEMENT DUE T.pdf
page 9 STAFF DISCUSSION OF THE RISK OF MATERIAL MISSTATEMENT DUE T.pdfpage 9 STAFF DISCUSSION OF THE RISK OF MATERIAL MISSTATEMENT DUE T.pdf
page 9 STAFF DISCUSSION OF THE RISK OF MATERIAL MISSTATEMENT DUE T.pdfalicesilverblr
 
page 8 III. OUTLINE OF STATEMENT ON AUDITING STANDARDS NO. 99, CON.pdf
page 8 III. OUTLINE OF STATEMENT ON AUDITING STANDARDS NO. 99, CON.pdfpage 8 III. OUTLINE OF STATEMENT ON AUDITING STANDARDS NO. 99, CON.pdf
page 8 III. OUTLINE OF STATEMENT ON AUDITING STANDARDS NO. 99, CON.pdfalicesilverblr
 
page 12 B. Conflicting or missing audit evidence, such as (1) Mis.pdf
page 12 B. Conflicting or missing audit evidence, such as (1) Mis.pdfpage 12 B. Conflicting or missing audit evidence, such as (1) Mis.pdf
page 12 B. Conflicting or missing audit evidence, such as (1) Mis.pdfalicesilverblr
 
page 10 (4) In-house legal counsel. E. Be aware in evaluating ma.pdf
page 10 (4) In-house legal counsel. E. Be aware in evaluating ma.pdfpage 10 (4) In-house legal counsel. E. Be aware in evaluating ma.pdf
page 10 (4) In-house legal counsel. E. Be aware in evaluating ma.pdfalicesilverblr
 
p14-15 34. The risk of fraud may be so high as to cause the audi.pdf
p14-15 34. The risk of fraud may be so high as to cause the audi.pdfp14-15 34. The risk of fraud may be so high as to cause the audi.pdf
p14-15 34. The risk of fraud may be so high as to cause the audi.pdfalicesilverblr
 
p13 29. The auditor should evaluate whether analytical procedure.pdf
p13 29. The auditor should evaluate whether analytical procedure.pdfp13 29. The auditor should evaluate whether analytical procedure.pdf
p13 29. The auditor should evaluate whether analytical procedure.pdfalicesilverblr
 
P1 Una entidad adquiere un elemento de equipo que no es de naturale.pdf
P1 Una entidad adquiere un elemento de equipo que no es de naturale.pdfP1 Una entidad adquiere un elemento de equipo que no es de naturale.pdf
P1 Una entidad adquiere un elemento de equipo que no es de naturale.pdfalicesilverblr
 
Owner, Andy Pforzheimer, holds a meeting with his employees in which.pdf
Owner, Andy Pforzheimer, holds a meeting with his employees in which.pdfOwner, Andy Pforzheimer, holds a meeting with his employees in which.pdf
Owner, Andy Pforzheimer, holds a meeting with his employees in which.pdfalicesilverblr
 
ow Effective Managers Use Information Systems Advances in computer-b.pdf
ow Effective Managers Use Information Systems Advances in computer-b.pdfow Effective Managers Use Information Systems Advances in computer-b.pdf
ow Effective Managers Use Information Systems Advances in computer-b.pdfalicesilverblr
 
Overview of the Animal Kingdom (ch. 32)a. Describe the origins and.pdf
Overview of the Animal Kingdom (ch. 32)a. Describe the origins and.pdfOverview of the Animal Kingdom (ch. 32)a. Describe the origins and.pdf
Overview of the Animal Kingdom (ch. 32)a. Describe the origins and.pdfalicesilverblr
 
Over the past ten years, if you had an innovative product like �EarP.pdf
Over the past ten years, if you had an innovative product like �EarP.pdfOver the past ten years, if you had an innovative product like �EarP.pdf
Over the past ten years, if you had an innovative product like �EarP.pdfalicesilverblr
 
OTEL RIXOS PREMIUM BELEK OTEL POZSYON PAZARLAMA EKB COVID-19d.pdf
OTEL RIXOS PREMIUM BELEK OTEL POZSYON PAZARLAMA EKB COVID-19d.pdfOTEL RIXOS PREMIUM BELEK OTEL POZSYON PAZARLAMA EKB COVID-19d.pdf
OTEL RIXOS PREMIUM BELEK OTEL POZSYON PAZARLAMA EKB COVID-19d.pdfalicesilverblr
 
other information provided is the answer for T T=-0.62 i still ne.pdf
other information provided is the answer for T T=-0.62 i still ne.pdfother information provided is the answer for T T=-0.62 i still ne.pdf
other information provided is the answer for T T=-0.62 i still ne.pdfalicesilverblr
 
Please complete the fill in the box exercise by identify the federal.pdf
Please complete the fill in the box exercise by identify the federal.pdfPlease complete the fill in the box exercise by identify the federal.pdf
Please complete the fill in the box exercise by identify the federal.pdfalicesilverblr
 

Plus de alicesilverblr (20)

Part B Vulnerability Management Plan To prepare a vulnerability.pdf
Part B Vulnerability Management Plan To prepare a vulnerability.pdfPart B Vulnerability Management Plan To prepare a vulnerability.pdf
Part B Vulnerability Management Plan To prepare a vulnerability.pdf
 
Part 1 � 10 marksAster Turane Computers uses a perpetual accountin.pdf
Part 1 � 10 marksAster Turane Computers uses a perpetual accountin.pdfPart 1 � 10 marksAster Turane Computers uses a perpetual accountin.pdf
Part 1 � 10 marksAster Turane Computers uses a perpetual accountin.pdf
 
Part 1 Refer to pages 92-100 in your text as you answer these quest.pdf
Part 1 Refer to pages 92-100 in your text as you answer these quest.pdfPart 1 Refer to pages 92-100 in your text as you answer these quest.pdf
Part 1 Refer to pages 92-100 in your text as you answer these quest.pdf
 
Para arz B�y�k Buhran srasnda d�t� ��nk� __________. Yant se�enekl.pdf
Para arz B�y�k Buhran srasnda d�t� ��nk� __________. Yant se�enekl.pdfPara arz B�y�k Buhran srasnda d�t� ��nk� __________. Yant se�enekl.pdf
Para arz B�y�k Buhran srasnda d�t� ��nk� __________. Yant se�enekl.pdf
 
Pandas is a Python library used for working with data sets. It has f.pdf
Pandas is a Python library used for working with data sets. It has f.pdfPandas is a Python library used for working with data sets. It has f.pdf
Pandas is a Python library used for working with data sets. It has f.pdf
 
page 6-7 Fraud (previously referred to as irregularities) -Inten.pdf
page 6-7 Fraud (previously referred to as irregularities) -Inten.pdfpage 6-7 Fraud (previously referred to as irregularities) -Inten.pdf
page 6-7 Fraud (previously referred to as irregularities) -Inten.pdf
 
page 9 STAFF DISCUSSION OF THE RISK OF MATERIAL MISSTATEMENT DUE T.pdf
page 9 STAFF DISCUSSION OF THE RISK OF MATERIAL MISSTATEMENT DUE T.pdfpage 9 STAFF DISCUSSION OF THE RISK OF MATERIAL MISSTATEMENT DUE T.pdf
page 9 STAFF DISCUSSION OF THE RISK OF MATERIAL MISSTATEMENT DUE T.pdf
 
page 8 III. OUTLINE OF STATEMENT ON AUDITING STANDARDS NO. 99, CON.pdf
page 8 III. OUTLINE OF STATEMENT ON AUDITING STANDARDS NO. 99, CON.pdfpage 8 III. OUTLINE OF STATEMENT ON AUDITING STANDARDS NO. 99, CON.pdf
page 8 III. OUTLINE OF STATEMENT ON AUDITING STANDARDS NO. 99, CON.pdf
 
page 12 B. Conflicting or missing audit evidence, such as (1) Mis.pdf
page 12 B. Conflicting or missing audit evidence, such as (1) Mis.pdfpage 12 B. Conflicting or missing audit evidence, such as (1) Mis.pdf
page 12 B. Conflicting or missing audit evidence, such as (1) Mis.pdf
 
page 10 (4) In-house legal counsel. E. Be aware in evaluating ma.pdf
page 10 (4) In-house legal counsel. E. Be aware in evaluating ma.pdfpage 10 (4) In-house legal counsel. E. Be aware in evaluating ma.pdf
page 10 (4) In-house legal counsel. E. Be aware in evaluating ma.pdf
 
p14-15 34. The risk of fraud may be so high as to cause the audi.pdf
p14-15 34. The risk of fraud may be so high as to cause the audi.pdfp14-15 34. The risk of fraud may be so high as to cause the audi.pdf
p14-15 34. The risk of fraud may be so high as to cause the audi.pdf
 
p13 29. The auditor should evaluate whether analytical procedure.pdf
p13 29. The auditor should evaluate whether analytical procedure.pdfp13 29. The auditor should evaluate whether analytical procedure.pdf
p13 29. The auditor should evaluate whether analytical procedure.pdf
 
P1 Una entidad adquiere un elemento de equipo que no es de naturale.pdf
P1 Una entidad adquiere un elemento de equipo que no es de naturale.pdfP1 Una entidad adquiere un elemento de equipo que no es de naturale.pdf
P1 Una entidad adquiere un elemento de equipo que no es de naturale.pdf
 
Owner, Andy Pforzheimer, holds a meeting with his employees in which.pdf
Owner, Andy Pforzheimer, holds a meeting with his employees in which.pdfOwner, Andy Pforzheimer, holds a meeting with his employees in which.pdf
Owner, Andy Pforzheimer, holds a meeting with his employees in which.pdf
 
ow Effective Managers Use Information Systems Advances in computer-b.pdf
ow Effective Managers Use Information Systems Advances in computer-b.pdfow Effective Managers Use Information Systems Advances in computer-b.pdf
ow Effective Managers Use Information Systems Advances in computer-b.pdf
 
Overview of the Animal Kingdom (ch. 32)a. Describe the origins and.pdf
Overview of the Animal Kingdom (ch. 32)a. Describe the origins and.pdfOverview of the Animal Kingdom (ch. 32)a. Describe the origins and.pdf
Overview of the Animal Kingdom (ch. 32)a. Describe the origins and.pdf
 
Over the past ten years, if you had an innovative product like �EarP.pdf
Over the past ten years, if you had an innovative product like �EarP.pdfOver the past ten years, if you had an innovative product like �EarP.pdf
Over the past ten years, if you had an innovative product like �EarP.pdf
 
OTEL RIXOS PREMIUM BELEK OTEL POZSYON PAZARLAMA EKB COVID-19d.pdf
OTEL RIXOS PREMIUM BELEK OTEL POZSYON PAZARLAMA EKB COVID-19d.pdfOTEL RIXOS PREMIUM BELEK OTEL POZSYON PAZARLAMA EKB COVID-19d.pdf
OTEL RIXOS PREMIUM BELEK OTEL POZSYON PAZARLAMA EKB COVID-19d.pdf
 
other information provided is the answer for T T=-0.62 i still ne.pdf
other information provided is the answer for T T=-0.62 i still ne.pdfother information provided is the answer for T T=-0.62 i still ne.pdf
other information provided is the answer for T T=-0.62 i still ne.pdf
 
Please complete the fill in the box exercise by identify the federal.pdf
Please complete the fill in the box exercise by identify the federal.pdfPlease complete the fill in the box exercise by identify the federal.pdf
Please complete the fill in the box exercise by identify the federal.pdf
 

Dernier

Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxVishalSingh1417
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxDenish Jangid
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDThiyagu K
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxAreebaZafar22
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfagholdier
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingTechSoup
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.pptRamjanShidvankar
 
psychiatric nursing HISTORY COLLECTION .docx
psychiatric  nursing HISTORY  COLLECTION  .docxpsychiatric  nursing HISTORY  COLLECTION  .docx
psychiatric nursing HISTORY COLLECTION .docxPoojaSen20
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAssociation for Project Management
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxiammrhaywood
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxheathfieldcps1
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17Celine George
 
Unit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxUnit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxVishalSingh1417
 
fourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writingfourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writingTeacherCyreneCayanan
 
Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Disha Kariya
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxVishalSingh1417
 
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...Shubhangi Sonawane
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introductionMaksud Ahmed
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...EduSkills OECD
 

Dernier (20)

Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
 
Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptx
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SD
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptx
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.ppt
 
psychiatric nursing HISTORY COLLECTION .docx
psychiatric  nursing HISTORY  COLLECTION  .docxpsychiatric  nursing HISTORY  COLLECTION  .docx
psychiatric nursing HISTORY COLLECTION .docx
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across Sectors
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17
 
Unit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxUnit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptx
 
fourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writingfourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writing
 
Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptx
 
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
 

PLEASE ANSWER IN PYTHONIn this assignment you will be adding to th.pdf

  • 1. PLEASE ANSWER IN PYTHON In this assignment you will be adding to the classes Node and Tree that we developed in Binary Search Tree Lecture and testing them. There are several short methods that you will have to write. Write a method range() that returns the range of values stored in a binary search tree of integers. The range of values equals the maximum value in the binary search tree minus the minimum value. If there is one value in the tree the range is 0. If the tree is empty the range is undefined. def range (self): Write a method get level() that takes as input the level and returns a list of all the nodes at that level from left to right. If that level does not exist for that binary search tree return an empty list . Use the convention that the root is at level 0. def get level (self, level): Write a method left side view() when given the root of a binary tree, imagine yourself standing on the left side of it, return the values of the nodes you can see ordered from top to bottom. def left side view (self): Write a method sum leaf nodes() that returns the sum of the value of all leaves. Recall that a leaf node does not have any children. def sum leaf node (self): In this assignment you will be writing helper methods for the Tree class that we developed and test them. The following is the outline of the code that you will be submitting. You may include the other functions that we developed for completeness. Input: 50 30 70 10 40 60 80 7 25 38 47 58 65 77 96 50 30 70 10 40 60 80 7 25 38 47 58 65 77 96 58 77 65 30 38 50 7 25 47 96 80 10 60 70 40 Starter Code
  • 2. import sys class Node (object): # constructor def __init__(self, data): self.data = data self.lChild = None self.rChild = None def print_node(self, level=0): if self.lChild != None: self.lChild.print_node(level + 1) print(' ' * 3 * level + '->', self.data) if self.rChild != None: self.rChild.print_node(level + 1) def get_height(self): if self.lChild != None and self.rChild != None: return 1 + max(self.lChild.get_height(), self.rChild.get_height()) elif self.lChild != None: return 1 + self.lChild.get_height() elif self.rChild != None: return 1 + self.rChild.get_height() else: return 1 class Tree(object): # constructor def __init__(self): self.root = None def print(self, level): self.root.print_node(level) def get_height(self): return self.root.get_height() # Inserts data into Binary Search Tree and creates a valid BST def insert(self, data): new_node = Node(data) if self.root == None: self.root = new_node return
  • 3. else: parent = self.root curr = self.root # finds location to insert new node while curr != None: parent = curr if data < curr.data: curr = curr.lChild else: curr = curr.rChild # inserts new node based on comparision to parent node if data < parent.data: parent.lChild = new_node else: parent.rChild = new_node return # Returns the range of values stored in a binary search tree of integers. # The range of values equals the maximum value in the binary search tree minus the minimum value. # If there is one value in the tree the range is 0. If the tree is empty the range is undefined. def range(self): # Returns a list of nodes at a given level from left to right def get_level(self, level): # Returns the list of the node that you see from left side # The order of the output should be from top to down def left_side_view(self): # returns the sum of the value of all leaves. # a leaf node does not have any children. def sum_leaf_nodes(self): def make_tree(data): tree = Tree() for d in data: tree.insert(d) return tree # Develop your own main function or test cases to be able to develop.
  • 4. # Our tests on the Gradescop will import your classes and call the methods. def main(): # Create three trees - two are the same and the third is different line = sys.stdin.readline() line = line.strip() line = line.split() tree1_input = list(map(int, line)) # converts elements into ints t1 = make_tree(tree1_input) t1.print(t1.get_height()) print("Tree range is: ", t1.range()) print("Tree left side view is: ", t1.left_side_view()) print("Sum of leaf nodes is: ", t1.sum_leaf_nodes()) print("##########################") # Another Tree for test. line = sys.stdin.readline() line = line.strip() line = line.split() tree2_input = list(map(int, line)) # converts elements into ints t2 = make_tree(tree2_input) t2.print(t2.get_height()) print("Tree range is: ", t2.range()) print("Tree left side view is: ", t2.left_side_view()) print("Sum of leaf nodes is: ", t2.sum_leaf_nodes()) print("##########################") # Another Tree line = sys.stdin.readline() line = line.strip() line = line.split() tree3_input = list(map(int, line)) # converts elements into ints t3 = make_tree(tree3_input) t3.print(t3.get_height()) print("Tree range is: ", t3.range()) print("Tree left side view is: ", t3.left_side_view()) print("Sum of leaf nodes is: ", t3.sum_leaf_nodes()) print("##########################") if __name__ == "__main__":