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 scanning many nodes, losing the efficiency BSTs provide. These operations are essential in many applications like range queries, nearest neighbor searches, and decision-making systems where approximate matches matter. They make BSTs more powerful and practical in real-world 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 more complex tree operations like range queries, predecessor and successor finding, and balanced BSTs like AVL or Red-Black trees.