Skip to content
Official PYQ · 2025

GATE CS 2025 Set 2 Q31 — Searching, Sorting, Hashing

Explain with AI

​​An array AA of length nn with distinct elements is said to be bitonic if there is an index 1≤i≤n1 \leq i \leq n such that A[1..i]A[1 . . i] is sorted in the non-decreasing order and A[i+1…n]A[i+1 \ldots n] is sorted in the non-increasing order.

Which ONE of the following represents the best possible asymptotic bound for the worst-case number of comparisons by an algorithm that searches for an element in a bitonic array AA ?

Choose one option
View worked solution

Answer: D

To find an element in a bitonic array AA of size nn, we can design an efficient algorithm using a divide-and-conquer approach in two main steps:

  1. Find the peak element (index ii): The peak element is the maximum element where the array transitions from increasing to decreasing. We can find this peak using a modified binary search:
    • Compare the middle element A[mid]A[mid] with its neighbors A[mid−1]A[mid-1] and A[mid+1]A[mid+1].
    • If A[mid−1]<A[mid]>A[mid+1]A[mid-1] < A[mid] > A[mid+1], then A[mid]A[mid] is the peak.
    • If A[mid−1]<A[mid]<A[mid+1]A[mid-1] < A[mid] < A[mid+1], the peak lies in the right half.
    • If A[mid−1]>A[mid]>A[mid+1]A[mid-1] > A[mid] > A[mid+1], the peak lies in the left half.
    This step takes Θ(log⁡n)\Theta(\log n) comparisons in the worst case.
  2. Search for the target element: Once the peak index ii is identified, the array is split into two sorted subarrays:
    • A[1…i]A[1 \ldots i] which is sorted in increasing order.
    • A[i+1…n]A[i+1 \ldots n] which is sorted in decreasing order.
    We can perform a standard binary search on A[1…i]A[1 \ldots i] and a descending binary search on A[i+1…n]A[i+1 \ldots n]. Each of these searches takes Θ(log⁡n)\Theta(\log n) comparisons in the worst case.

Total Complexity:

The total number of comparisons in the worst case is:

Total Comparisons=Θ(log⁡n) (to find peak)+Θ(log⁡n) (to search)=Θ(log⁡n)\text{Total Comparisons} = \Theta(\log n) \text{ (to find peak)} + \Theta(\log n) \text{ (to search)} = \Theta(\log n)

Since any comparison-based search in a sorted array of size nn requires at least Ω(log⁡n)\Omega(\log n) comparisons in the worst case, the best possible asymptotic bound for the worst-case number of comparisons is Θ(log⁡n)\Theta(\log n).

Free practice · Your answers on this page are not saved.

Published
Report a correction
Keep exploringMore Searching, Sorting, Hashing questions