Machine-translated by Google. Questions are authored in English.
Top

Discussion

An array \(A\) of length \(n\) with distinct elements is said to be bitonic if there is an index \(1 \le i \le n\) such that \(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\)?

  • A.\(\Theta(n)\)
  • B.\(\Theta(1)\)
  • C.\(\Theta(\log^{2} n)\)
  • D.\(\Theta(\log n)\)

Answer: D

The best bound is Θ(log n).

A search in a bitonic array can be done in three binary searches:

  1. Find the peak, the index where the array stops increasing: compare A[mid] with A[mid + 1] and move towards the larger one. O(log n) comparisons.
  2. Binary search the increasing part A[1..peak].
  3. Binary search the decreasing part with the comparison reversed.

That is O(log n) in all, and Ω(log n) is unavoidable because a sorted array is a special case of a bitonic one, and searching it needs log n comparisons. Θ(n) is a linear scan, Θ(1) is impossible, and Θ(log2 n) is what one gets by searching without first finding the peak, which is not optimal.

No comment is present. Be the first to comment.
Loading…

Post your comment

Please log in or register to post a comment.