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 closest values in sorted data stored in a BST.
Why it matters
Without floor and ceil operations, finding closest values in a sorted collection would require scanning all elements, which is slow. Floor and ceil let us find these closest values efficiently using the BST's structure. This is useful in many real-world tasks like searching ranges, nearest neighbor queries, and decision making based on thresholds.
Where it fits
Before learning floor and ceil in BST, you should understand what a BST is and how it stores data in a sorted way. After this, you can learn about more complex tree operations like range queries, predecessor and successor, and balanced BSTs for faster performance.