Question: python!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! we have 1 hour Question 3 (2 Sections) 40 points 45 mins In this question you will write two functions with identical functionality, that
python!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! we have 1 hour


Question 3 (2 Sections) 40 points 45 mins In this question you will write two functions with identical functionality, that is, to return the depth of a given binary tree, whose root node is given as argument. Implement tree_depth_i( root ) that strictly uses iteration looping (_i) to accomplish the task Implement tree_depth_r( root ) that strictly uses recursion (r) to accomplish this task Both functions should return o if there is only a single (root) node in the provided binary tree. 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 3.1: Implement tree_depth_i() Since the following code cell uses the file magic, running the following cell will create a file named tree_depth_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 tree_depth_i.py def tree_depth_i( root ): An iterative function that returns the depth of the provided binary tree as an integer. The root of a binary tree is at depth o. # YOUR CODE HERE raise Not ImplementedError() TESTS ## TEST #3.1.1 from tree_depth_i import tree_depth_i student_answer tree_depth_i(A) correct answer = 6 assert student answer == correct answer print(">>> TEST PASSED >> TEST PASSED >> TEST PASSED >> TEST PASSED
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
