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

Searching Algorithms Questions and Answers

1.

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\)?

Exam Year(s)

GATE CS - 2025,

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.

Please log in or register to report this question.

2.

The extra key inserted at the end of the array is called a/an :

Exam Year(s)

MH SET - 2018, SET Exam - 2018,

Answer: C

The extra key is called a sentinel.

In a sentinel search the value being looked for is placed in an extra position at the end of the array before a linear search starts. The loop can then compare elements with the key without also checking at every step whether the index has passed the end, because the search is certain to stop at the sentinel. If it stops there, the key was not in the original array.

'End key' and 'stop key' are not the standard terms, and transposition is a self-organising search heuristic that swaps a found item with its predecessor.

Please log in or register to report this question.

3.

A technique for direct search is :

Exam Year(s)

MH SET - 2019, SET Exam - 2019,

Answer: C

The direct search technique is Hashing.

Hashing computes the storage address of a record directly from its key by a hash function, so in the ideal case the item is reached in one step, O(1), without comparing it with other keys.

Linear search compares the key with items one by one, binary search halves a sorted list by comparison at each step, and tree search follows a path of comparisons from the root. All three are comparison-based searches rather than direct ones.

Please log in or register to report this question.

4.

Working modulo q = 11, how many spurious hits does the Rabin Karp matcher encounter in the text T = 459263781 when working for the pattern β = 37 :

Exam Year(s)

MH SET - 2019, SET Exam - 2019,

Answer: C

The matcher encounters 4 spurious hits.

The pattern's hash is 37 mod 11 = 4. Rabin-Karp compares this with the hash of every two-digit window of the text 459263781:

4559922663377881
14448414

Five windows hash to 4: 59, 92, 26, 37 and 81. Only 37 is a real match. The other four, 59, 92, 26 and 81, are spurious hits: their hash agrees with the pattern's but the digits do not.

Counting the true match as well gives 5, which is the trap in option D.

Please log in or register to report this question.

5.

For binary search algorithm, which of the following is not a required condition ?

Exam Year(s)

MH SET - 2024, SET Exam - 2024,

Answer: B

The condition that is not required is an easy mechanism to delete and/or insert elements.

Binary search requires the list to be sorted and needs direct access to the middle element of any sublist, which is why it suits arrays and not linked lists.

Ease of insertion and deletion is not needed to search; arrays make insertion costly and binary search still works on them. So options A and C are requirements, and 'None of the above' is wrong because B is not one.

Please log in or register to report this question.

Loading…
Tags: Searching Algorithms Questions and Answers || Searching Algorithms MCQ Questions and Answers || Searching Algorithms GK Questions and Answers || Searching Algorithms GK MCQ Questions || Searching Algorithms Multiple Choice Questions and Answers || Searching Algorithms GK || GK on Searching Algorithms || Data Structures and Algorithms Questions and Answers || Data Structures and Algorithms MCQ Questions and Answers || Data Structures and Algorithms GK Questions and Answers || GK on Data Structures and Algorithms