Answered step by step
Verified Expert Solution
Question
1 Approved Answer
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 HOUR
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 PASSEDStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started