Floor and Ceil in BST
📖 Scenario: You are working with a Binary Search Tree (BST) that stores integer values. You want to find two special values for a given number:Floor: The greatest value in the BST less than or equal to the given number.Ceil: The smallest value in the BST greater than or equal to the given number.This is useful in many real-world cases like searching for closest available prices or dates.
🎯 Goal: Build a program that creates a BST with given values, sets a target number, and finds the floor and ceil values in the BST for that target.
📋 What You'll Learn
Create a BST by inserting nodes with exact values: 8, 4, 12, 2, 6, 10, 14
Create an integer variable called
target and set it to 5Write two functions
findFloor and findCeil that find floor and ceil values in the BST for targetPrint the floor and ceil values exactly as:
Floor: X and Ceil: Y💡 Why This Matters
🌍 Real World
Finding floor and ceil values in sorted data is common in price matching, scheduling, and recommendation systems.
💼 Career
Understanding BST operations and search algorithms is essential for software engineering roles involving data structures and algorithm optimization.
Progress0 / 4 steps