Question: PYTHON !!!!!!!!!!!!!!!!!!!!!!!!!!! WE HAVE 1 HOUR Question 2 (2 Sections) 40 points 45 mins In this question you will write two functions with identical functionality,

PYTHON !!!!!!!!!!!!!!!!!!!!!!!!!!! WE HAVE 1 HOURPYTHON !!!!!!!!!!!!!!!!!!!!!!!!!!! WE HAVE 1 HOUR Question 2 (2 Sections) 40 points45 mins In this question you will write two functions with identical

Question 2 (2 Sections) 40 points 45 mins In this question you will write two functions with identical functionality, that is, to return a list of all leaf nodes in a given binary tree. Implement get_leaf_nodes_i( root ) that strictly uses iteration looping (i ) to accomplish this task Implement get_leaf_nodes_r( root ) that strictly uses recursion (_r) to accomplish this task Both functions should return an empty list if the provided treeode does not have any children. You are to write both functions from scratch. This means your code should contain no import statements! WARNING If you write these functions disregarding the strict specifications mentioned above, you will not get any credit for your solutions, even if they happen to "work." Section 2.1: Implement get_leaf_nodes_i() Since the following code cell uses the file magic, runnig the following cell will create a file named get_leaf_nodes_i.py. For testing, you must not modify the file magic directive at the top of the following cell. YOU MUST WRITE YOUR CODE IN THE FOLLOWING CODE CELL ]: %%file get_leaf_nodes_i.py def get_leaf_nodes_i( root ): # YOUR CODE HERE raise NotImplementedError() TESTS TEST #2.1.1 # # # from get_leaf_nodes_i import get_leaf_nodes_i student_answer = sorted( get_leaf_nodes_i( A ), key=lambda n: n.value) correct answer = sorted( [M, L, R, N, I, H, E] ) assert student_answer == correct_answer print( ">>> TEST PASSED >> TEST PASSED >> TEST PASSED

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!