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 in 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 checking many nodes manually, which is slow. Floor and ceil let us answer these questions fast, which is useful in many real-world tasks like searching, range queries, and decision making. They make BSTs more powerful and practical.
Where it fits
Before learning floor and ceil, you should understand what a Binary Search Tree is and how it organizes data. After mastering floor and ceil, you can explore more complex tree queries like range searches, predecessor and successor nodes, and balanced BSTs like AVL or Red-Black trees.
