Recall & Review
beginner
What is a peak element in an array?
A peak element is an element that is greater than its neighbors. For the first or last element, only one neighbor is considered.
Click to reveal answer
intermediate
Why is binary search suitable for finding a peak element?
Because if an element is not a peak, we can decide which side to move based on the neighbor's value, reducing the search space by half each time.
Click to reveal answer
beginner
In the binary search for peak element, if mid element is less than its right neighbor, which side do we search next?
We search the right half because a peak must exist there.
Click to reveal answer
beginner
What is the time complexity of finding a peak element using binary search?
O(log n), where n is the number of elements in the array.
Click to reveal answer
beginner
Show the base condition to stop the binary search when finding a peak element.
When the search space reduces to one element, that element is a peak.
Click to reveal answer
What defines a peak element in an array?
✗ Incorrect
A peak element is one that is greater than its neighbors.
If mid element is less than its left neighbor, where should binary search continue?
✗ Incorrect
Search left half because a peak exists there.
What is the worst-case time complexity of binary search for peak element?
✗ Incorrect
Binary search reduces search space by half each step, so O(log n).
Can the first or last element be a peak element?
✗ Incorrect
First or last element can be peak if greater than their single neighbor.
What happens if mid element is greater than both neighbors?
✗ Incorrect
If mid is greater than neighbors, it is a peak.
Explain how binary search helps find a peak element in an array.
Think about how neighbors guide the search direction.
You got /4 concepts.
Describe the steps and conditions to implement binary search for finding a peak element.
Focus on the loop and decision making.
You got /5 concepts.