Question: 1. You can write either the code or pseudocode. Let the BinarySearchTree class be defined as follows: class BinarySearchTree { class Tree { int element;
1. You can write either the code or pseudocode.
Let the BinarySearchTree class be defined as follows: class BinarySearchTree { class Tree { int element; Tree left, right; Tree(int x, Tree l, Tree r) { element = x; left = l; right = r; } } Tree root; // root of binary search tree int size; // number of elements in the BST BinarySearchTree() { // constructor root = null; size = 0; } BinarySearchTree(Tree t, int s) { // constructor root = t; size = s; } } 1. Given a binary search tree of integers, and an integer x, write the functions floor and ceiling. Hint: If x is not in the tree, the floor and ceiling elements are on the path taken by find(x). // Class to store 2 integers class Pair { int floor, ceiling; Pair(int f, int c) { floor = f; ceiling = c; } } // Floor: largest element of the BST that is less than or equal to x // Ceiling: smallest element of the BST that is greater than or equal to x Pair floorAndCeiling(BinarySearchTree t, int x) { /* To do */ } Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
