Overview - Floor and Ceil in BST
What is it?
Floor and Ceil in a Binary Search Tree (BST) are two special values related to a given number. The floor is the greatest value in the BST that is less than or equal to the given number. The ceil is the smallest value in the BST that is greater than or equal to the given number. These help us quickly find close matches to a number inside a sorted tree structure.
Why it matters
Without floor and ceil, finding the closest smaller or larger value to a number in a BST would require scanning many nodes, losing the speed advantage of BSTs. These operations allow fast queries like 'find the nearest available price less than or equal to my budget' or 'find the next available appointment after a given time'. They make BSTs practical for many real-world searching problems.
Where it fits
Before learning floor and ceil, you should understand what a Binary Search Tree is and how searching works in it. After mastering floor and ceil, you can explore range queries, nearest neighbor searches, and balanced BSTs like AVL or Red-Black trees for efficient dynamic data handling.
