Recall & Review
beginner
What is the floor of a number in a sorted array?
The floor of a number is the greatest element in the array that is less than or equal to that number.
Click to reveal answer
beginner
What is the ceil of a number in a sorted array?
The ceil of a number is the smallest element in the array that is greater than or equal to that number.
Click to reveal answer
intermediate
Why is binary search useful for finding floor and ceil in a sorted array?
Binary search helps find floor and ceil efficiently by repeatedly dividing the search space in half, reducing time complexity to O(log n).
Click to reveal answer
intermediate
If the target number is smaller than all elements in the array, what is the floor and ceil?
Floor does not exist (no element ≤ target), ceil is the smallest element in the array.
Click to reveal answer
intermediate
If the target number is larger than all elements in the array, what is the floor and ceil?
Floor is the largest element in the array, ceil does not exist (no element ≥ target).
Click to reveal answer
What does the floor of 7 mean in the sorted array [1, 3, 5, 8, 10]?
✗ Incorrect
Floor is the greatest element less than or equal to the target, so here it is 5.
What is the ceil of 6 in the sorted array [2, 4, 6, 8, 10]?
✗ Incorrect
Ceil is the smallest element greater than or equal to 6, which is 6 itself.
If the target is 0 and the array is [5, 10, 15], what is the floor?
✗ Incorrect
No element is less than or equal to 0, so floor does not exist.
Which algorithm is best to find floor and ceil in a sorted array efficiently?
✗ Incorrect
Binary search reduces the search space quickly, making it efficient for this task.
If the target is 20 and the array is [1, 5, 10, 15], what is the ceil?
✗ Incorrect
No element is greater than or equal to 20, so ceil does not exist.
Explain how to find the floor and ceil of a number in a sorted array using binary search.
Think about how to move left or right in the array to find closest smaller or larger elements.
You got /4 concepts.
Describe what happens when the target number is smaller than all elements or larger than all elements in the array regarding floor and ceil.
Consider the array boundaries and what floor and ceil mean.
You got /4 concepts.