Answered step by step
Verified Expert Solution
Link Copied!

Question

00
1 Approved Answer

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 image text in transcribed

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

Step: 1

blur-text-image

Get Instant Access with AI-Powered 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

Students also viewed these Databases questions

Question

is relaxation training effective treatment options for veterans

Answered: 1 week ago