0
0
DSA Javascriptprogramming~5 mins

Floor and Ceil in Sorted Array in DSA Javascript - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
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]?
AThe number 7 itself
BThe smallest number ≥ 7
CThe largest number ≤ 7
DThe smallest number in the array
What is the ceil of 6 in the sorted array [2, 4, 6, 8, 10]?
A4
B10
C8
D6
If the target is 0 and the array is [5, 10, 15], what is the floor?
A0
BNo floor exists
C5
D15
Which algorithm is best to find floor and ceil in a sorted array efficiently?
ABinary search
BLinear search
CBubble sort
DInsertion sort
If the target is 20 and the array is [1, 5, 10, 15], what is the ceil?
ANo ceil exists
B20
C1
D15
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.