Question: need help with assignment Problem 1. Given a binary search tree of integers (positive and negative), BST, and an integer val, find the previous node

need help with assignment need help with assignment Problem 1. Given a binary search tree of

Problem 1. Given a binary search tree of integers (positive and negative), BST, and an integer val, find the previous node (i.e. in-order predecessor) and return the value of that node. Nodes in the BST do not have links to parents. Requirements: 1. Your program (functions) must run in O(log(n)-time (if a BST is balanced, then height of the tree is O(log(n)), where n is the size of the given BST Your public function must be called previous and take one parameter, the given integer, and return an integer, the value of the previous node int previous(int val); In all cases where previous node does not exist (BST is empty, the given node is the leftmost node of the given BST, the given value has not been found in the given BST), return INT MIN (defined in ) 2. 3. Example On Figure to the left, given a node 63, your program will return 62 (the previous node of 63 if the nodes were listed using in-order traversal) 60 62 41 74 If the given node is 74, then previous node is 70 53 If the given node is 16, then there are no previous node (16 is the smallest in the tree) 25 46 63 70 42 64

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!