Answered step by step
Verified Expert Solution
Question
1 Approved Answer
1. Write the function largest_loop( t) that receives a reference to the root of a binary search tree t and returns the largest key stored
1. Write the function largest_loop( t) that receives a reference to the root of a binary search tree t and returns the largest key stored in the tree. Your function must use a loop. 2. Write the function largest( t) that receives a reference to the root of a binary search tree t and returns the largest key stored in the tree. Your function must use recursion. 3. Write the function bst_to_dict (t,D) that receives a reference to the root of a binary search tree t and an initially empty dictionary D and adds to D all the keys stored in the tree and their addresses, such that D[k] is the address of the node where k is stored. You may assume there are no repeated elements in the tree. 4. Write the function num_children (t,k) that receives a reference to the root of a binary search tree t and an integer k and returns the number of children that the node containing k in the tree has, or 1 if k is not in t. You may assume that the tree contains no repeated elements. Hint: used the find function in the BST class. 5. Write the function path_to_largest (t) that receives a reference to the root of a binary search tree t and returns a list containing the keys in the path from the root of t to the largest key in t. You may assume that t is not empty. 6. Write the function path to_ k(t,k) that receives a reference to the root of a binary search tree t and an integer k and returns a list containing the keys in the path from the root of t to the node containing k. You may assume that k is in the tree. 7. Write the function leaves (t) that receives a reference to the root of a binary search tree t and returns a list containing all the keys that are stored in leaf nodes in t
Step 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