Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

USING PYTHON 3: write the code for the following Question with the following ADT operations. def create(data, left= None , right= None ): Create

USING PYTHON 3: write the code for the following Question with the following ADT operations.

image text in transcribed

 def create(data, left=None, right=None): """  Create a new treenode for the given data.  Pre-conditions:  data: Any data value to be stored in the treenode  left: Another treenode (or None, by default)  Post-condition:  none  Return:  the treenode created  """  return {'data':data, 'left':left, 'right':right} def get_data(treenode): """  Retrieve the contents of the data field.  Pre-conditions:  node: a node created by create()  Post-conditions:  none  Return  the data value stored previously in the node  """  return treenode['data'] def get_left(tnode): """  Retrieve the contents of the left field.  Pre-conditions:  tnode: a treenode created by create()  Post-conditions:  none  Return  the value stored in left field  """  return tnode['left'] def get_right(tnode): """  Retrieve the contents of the right field.  Pre-conditions:  tnode: a treenode created by create()  Post-conditions:  none  Return  the value stored in right field  """  return tnode['right'] def set_data(tnode, val): """  Set the contents of the data field to val.  Pre-conditions:  tnode: a node created by create()  val: a data value to be stored  Post-conditions:  stores the new data value, replacing the existing value  Return  none  """  tnode['data'] = val def set_left(tnode, val): """  Set the contents of left field to val.  Pre-conditions:  tnode: a treenode created by create()  val: a treenode, or the value None  Post-conditions:  stores the val in left field, replacing the existing value  Return  none  """  tnode['left'] = val def set_right(tnode, val): """  Set the contents of right field to val.  Pre-conditions:  tnode: a treenode created by create()  val: a treenode, or the value None  Post-conditions:  stores the val in right field, replacing the existing value  Return  none  """  tnode['right'] = val 

EXAMPLE TREE BINARY:

fibonatree = tn.create(5,tn.create(2,tn.create(1,None,None), tn.create(1,tn.create(0,None,None), tn.create(1,None,None))), tn.create(3,tn.create(1,tn.create(0,None,None), tn.create(1,None,None)), tn.create(2,tn.create(1,None,None), tn.create(1,tn.create(0,None,None), tn.create(1,None,None))))) 
Purpose: To do more thinking about binary trees Degree of Difficulty: Moderate We say that two binary trees ti and t2 satisfy the mirror property if all of the following conditions are true: 1 The data value stored in the root of t? is equal to the data value stored in the root of t2 2. The left subtree of t? and the right subtree of t2 satisfy the mirror property. 3. The right subtree of t1 and the left subtree of t2 satisfy the mirror property. If both ti and t2 are empty. we say the mirror property is satisfied, but if one is empty but the other is not, the mirror property is not satisfied. Write a function mirrored(t1, t2) that returns True if the two given trees satisfy the mirror property. and False otherwise. Purpose: To do more thinking about binary trees Degree of Difficulty: Moderate We say that two binary trees ti and t2 satisfy the mirror property if all of the following conditions are true: 1 The data value stored in the root of t? is equal to the data value stored in the root of t2 2. The left subtree of t? and the right subtree of t2 satisfy the mirror property. 3. The right subtree of t1 and the left subtree of t2 satisfy the mirror property. If both ti and t2 are empty. we say the mirror property is satisfied, but if one is empty but the other is not, the mirror property is not satisfied. Write a function mirrored(t1, t2) that returns True if the two given trees satisfy the mirror property. and False otherwise

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

Machine Learning And Knowledge Discovery In Databases European Conference Ecml Pkdd 2010 Barcelona Spain September 2010 Proceedings Part 1 Lnai 6321

Authors: Jose L. Balcazar ,Francesco Bonchi ,Aristides Gionis ,Michele Sebag

2010th Edition

364215879X, 978-3642158797

More Books

Students also viewed these Databases questions

Question

Explain the forces that influence how people handle conflict

Answered: 1 week ago