Array · Data Structures
17 questions · asked in 12 of 27 years (2000–2026)
MCQ 15 · NAT 21-mark 13 · 2-mark 4
2000Questions per year2026
Questions 1–5 of 17
An array of length with distinct elements is said to be bitonic if there is an index such that is sorted in the non-decreasing order and 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 ?
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 ?
Answer: (D)
A bitonic array first rises and then falls, so its largest element (the peak) splits it into a rising part and a falling part.
Upper bound. Step 1: find the peak with a binary-search-like method. Look at the middle element and its neighbour . If , the peak is to the right. Otherwise it is at or to the left. This takes comparisons. Step 2: the rising part is sorted in increasing order and the falling part in decreasing order, so plain binary search on each takes . Total: .
Lower bound. A completely sorted array is also bitonic (the case ). Searching a sorted array needs comparisons in the worst case. So no algorithm for bitonic arrays can do better.
So the best worst-case bound is . is below the lower bound, and and are larger than needed.
Answer: (D)
Upper bound. Step 1: find the peak with a binary-search-like method. Look at the middle element and its neighbour . If , the peak is to the right. Otherwise it is at or to the left. This takes comparisons. Step 2: the rising part is sorted in increasing order and the falling part in decreasing order, so plain binary search on each takes . Total: .
Lower bound. A completely sorted array is also bitonic (the case ). Searching a sorted array needs comparisons in the worst case. So no algorithm for bitonic arrays can do better.
So the best worst-case bound is . is below the lower bound, and and are larger than needed.
Answer: (D)
Let be an array containing integer values. The distance of is defined as the minimum number of elements in that must be replaced with another integer so that the resulting array is sorted in non-decreasing order. The distance of the array is _____
Answer: 3
The elements we keep must already be in non-decreasing order. All the other elements can be replaced with suitable values. So
distance = (length of the longest non-decreasing subsequence).
In [2, 5, 3, 1, 4, 2, 6], the longest non-decreasing subsequence is 2, 3, 4, 6. Its length is 4.
So the distance (for example [2, 2, 3, 3, 4, 4, 6]).
Answer: 3
distance = (length of the longest non-decreasing subsequence).
In [2, 5, 3, 1, 4, 2, 6], the longest non-decreasing subsequence is 2, 3, 4, 6. Its length is 4.
So the distance (for example [2, 2, 3, 3, 4, 4, 6]).
Answer: 3
Let P be an array containing n integers. Let t be the lowest upper bound on the number of comparisons of the array elements, required to find the minimum and maximum values in an arbitrary array of n elements. Which one of the following choices is correct?
Answer: (C)
Take the elements two at a time. Compare the two with each other (1 comparison). Then compare the smaller one with the current minimum and the larger one with the current maximum (2 comparisons). That is 3 comparisons for every 2 elements. With the setup for the first pair, the total is comparisons. This is known to be the best possible, by an adversary argument. So .
Check against the options, for :
- Upper limit: , so .
- Lower limit: for even , when . For odd , when . So .
- (A) and (B) are wrong because is less than and less than . (D) is wrong because is more than .
Answer: (C)
Check against the options, for :
- Upper limit: , so .
- Lower limit: for even , when . For odd , when . So .
- (A) and (B) are wrong because is less than and less than . (D) is wrong because is more than .
Answer: (C)
What is the worst-case number of arithmetic operations performed by recursive binary search on a sorted array of size n?
Answer: (B)
In every recursive call, a fixed number of arithmetic operations is done (finding mid), and the range becomes half. So the recursion goes down to a depth of , and the total work is .
Answer:
Answer:
Let A be an array of 31 numbers consisting of sequence of 0's followed by a sequence of 1's. The problem is to find the smallest index i that A[i] is 1 by probing the minimum numbers of locations in A. The worst case number of probes performed by an optimal algorithm is _____________.
Answer: 5
The array is sorted, with all 0s first and then all 1s. So binary search can find the first 1.
There are 31 numbers. The first 1 can be at any of the 31 positions, or there may be no 1 at all. This gives 32 possible answers. The number of probes needed is .
Answer: 5
There are 31 numbers. The first 1 can be at any of the 31 positions, or there may be no 1 at all. This gives 32 possible answers. The number of probes needed is .
Answer: 5
Keep practising