target and set it to 16floorBST and ceilBST that find floor and ceil values for target in the BSTFloor: X and Ceil: Ytarget and set it to 16floorBST and ceilBST that find floor and ceil values for target in the BSTFloor: X and Ceil: YNode with int data, Node *left, and Node *right. Then write a function insertNode that inserts a new integer into the BST. Finally, create a BST by inserting these values in order: 20, 10, 30, 5, 15, 25, 35. Store the root in a variable called root.Start by defining the Node structure with data and pointers to left and right children. Then write a recursive insert function that places new values in the correct position. Insert the given values one by one into the BST.
target and set it to 16 inside the main function after building the BST.Inside the main function, declare an integer variable named target and assign it the value 16.
int floorBST(Node* root, int target) and int ceilBST(Node* root, int target). Each function should return the floor or ceil value for target in the BST. Use the BST property to traverse efficiently. Return -1 if floor or ceil does not exist.Use a loop to traverse the BST. For floor, move left if current node is greater than target, else update floor and move right. For ceil, move right if current node is less than target, else update ceil and move left. Return -1 if no floor or ceil found.
printf to print the floor and ceil values for target exactly as: Floor: X and Ceil: Y, where X and Y are the results from floorBST(root, target) and ceilBST(root, target).Call floorBST(root, target) and ceilBST(root, target) and store their results. Then print them using printf with the exact format Floor: X and Ceil: Y.
floor of a value in a Binary Search Tree (BST) represent?Node?Node* root and int key, returns int. Others have wrong parameter order, types, or return type.
10
/ \
5 15
/ \
12 20
int floorBST(Node* root, int key) {
if (!root) return -1;
if (root->data == key) return root->data;
if (root->data > key) return floorBST(root->left, key);
int floorValue = floorBST(root->right, key);
if (floorValue <= key && floorValue != -1) return floorValue;
else return root->data;
}
Pass the test and this pattern moves unknown