Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

In this question, you will implement a function named apply ( root, func), where root is the starting node of a given tree/subtree, which will

image text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribed

In this question, you will implement a function named apply ( root, func), where root is the starting node of a given tree/subtree, which will traverse the provided tree in breadth-first fashion strictly and apply the provided function, func to each node in that order. Your function will not return anything. Example: Suppose you are given the following tree, starting with root node, R order =1 \> def node_order( node ): global order node. order = order order +=1 > apply ( R, node_order ) R.order ==1 True >A.order ==2 True > B. order ==3 True J. order ==4 True P.order ==16 True T. order ==19 True - You must implement your entire code without using any external libraries/modules. In other words, your code should have absolutely no functioning import statements in itl That is, even if your code works perfectly with import statements despite this requirement, your grade for this exam will unfortunately be zero. The instructor will check for the use of import statements in your code in an automated fashion that you will not have access to. So please do not take a chance with this. Note that any deviation from any of these specifications will cost you points. Failure to abide by the strict programming rules mentioned here will result in zero grade automatically. For example, even if your code uses a single import statement, you will get a grade of zero for your work, and such a case will also be closed for any sort of appeal laterl You will use the above tree_node definition to define each node in the tree to be passed as argument to apply() ]: import string \# Create nodes named A-Z automagically \# for cur_letter in string.ascii_uppercase.replace( "R", " ): \# cur_node = tree_node( value=cur_letter*2) locals()[cur_letter] = cur_node B.children =[F,G,H] J.children =[K,L] D.children =[E] H. children =[M,N,0] L. children =[P,Q,S,T] []: order =1 def node_order( node): global order node. order = order order +=1 apply( R, node_order) [ ] : [] [ []: # # # order =1 def node_order( node): global order node.order order +=1 apply( order TEST 3

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

More Books

Students also viewed these Databases questions

Question

1. Define and explain culture and its impact on your communication

Answered: 1 week ago