Question Details

An array A of length n with distinct elements is said to be bitonic if there is an index 1 = i = n  such that A[1..i]A[1..i] is sorted in the non-decreasing order and A[i+1..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 A?

Options

A

Θ(n)

B

Θ(1)

C

Θ(log² n)

D

Θ(log n)

Show Answer

Correct Answer :

Option D

Θ(log n)

Solution :

The correct option is Θ(log n).

Let us understand why the worst-case number of comparisons for searching an element in a bitonic array is bounded by Θ(logn).

A bitonic array is an array that consists of distinct elements, which first increases monotonically up to a certain maximum element (the peak element at index i), and then decreases monotonically. Formally, A[1..i] is sorted in ascending order and A[i+1..n] is sorted in descending order.

To search for a target element in such an array efficiently, we can break down the process into two main phases, both utilizing modified binary search:

Step 1: Finding the peak element (the bitonic point)
We can find the index i of the peak element using a modified binary search. At each step, we look at the middle element A[m] and compare it with its neighbors:
- If A[m]>A[m-1] and A[m]>A[m+1], then A[m] is the peak.
- If A[m]>A[m-1] and A[m]<A[m+1], the peak must lie in the right half: A[m+1..n].
- If A[m]<A[m-1] and A[m]>A[m+1], the peak must lie in the left half: A[1..m-1].
Since we halve the search space at each step, finding the peak element takes Θ(logn) comparisons.

Step 2: Searching for the target element
Once the peak index i is identified, the array is split into two sorted subarrays:
1. An ascending sorted subarray A[1..i].
2. A descending sorted subarray A[i+1..n].
We perform a standard binary search for the target element on the ascending subarray, which takes Θ(logi) comparisons. If not found, we perform a binary search (adapted for descending order) on the descending subarray, which takes Θ(log(n-i)) comparisons.

Total Time Complexity:
The overall worst-case comparisons is the sum of the comparisons in both steps:
T(n)=Tfind_peak+Tsearch_ascending+Tsearch_descending
T(n)=Θ(logn)+Θ(logi)+Θ(log(n-i))
Since in and n-in, the complexity simplifies to:
T(n)=Θ(logn)

Thus, the best possible asymptotic bound for the worst-case number of comparisons is Θ(logn).

Unlock Our Free Library

Access expert-curated educational resources and study materials—completely free.

Ask AI Tutor
5 left
Q1 View Question & Options
AI Tutor is solving this question...
Reading question context & options...