Answered step by step
Verified Expert Solution
Link Copied!

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 HOURimage text in transcribedimage text in transcribed

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

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

Databases In Networked Information Systems 6th International Workshop Dnis 2010 Aizu Wakamatsu Japan March 2010 Proceedings Lncs 5999

Authors: Shinji Kikuchi ,Shelly Sachdeva ,Subhash Bhalla

2010th Edition

3642120377, 978-3642120374

More Books

Students also viewed these Databases questions

Question

3. Review together your differences and similarities.

Answered: 1 week ago