Searching Sorting and Hashing questions — page 1 of 2

Q24

GATE CS 2026 CS-1Searching Sorting and HashingMSQ1 mark
Consider a hash table P[0,1,…,10]P[0, 1, \dots, 10] that is initially empty. The hash table is maintained using open addressing with linear probing. The hash function used is
h(x)=(x+7)(mod11)h(x) = (x + 7) \pmod{11}.

Consider the following sequence of insertions performed on PP:
1,13,22,15,11,241, 13, 22, 15, 11, 24

Which of the following positions in the hash table is/are empty after these insertions are performed?
More than one option can be correct.
Show answer without attempting

Answer: C

Q30

GATE CS 2026 CS-2Searching Sorting and HashingNAT1 mark
The keys 5, 28, 19, 15, 26, 33, 12, 17, 10 are inserted into a hash table using the hash function h(k)=k mod 9h(k) = k \bmod 9. The collisions are resolved by chaining. After all the keys are inserted, the length of the longest chain is __________. (answer in integer)
Show answer without attempting

Answer: 3

Q32

GATE CS 2026 CS-2Searching Sorting and HashingNAT1 mark
Consider an array A=[10,7,8,19,41,35,25,31]A = [10, 7, 8, 19, 41, 35, 25, 31]. Suppose the merge sort algorithm is executed on array AA to sort it in increasing order. The merge sort algorithm will carry out a total of 7 merge operations.

A merge operation on sorted left array LL and sorted right array RR is said to be void if the output of the merge operation is the elements of array LL followed by the elements of array RR.

The number of void merge operations among these 7 merge operations is __________. (answer in integer)
Show answer without attempting

Answer: 3

Q33

GATE CS 2025 CS-1Searching Sorting and HashingNAT1 mark
The pseudocode of a function fun() is given below:
fun(int A[0,\dots,n-1]){
 for i=0 to n-2
 for j=0 to n-i-2
 if (A[j]>A[j+1])
 then swap A[j] and A[j+1]
}
Let A[0,…,29]A[0, \dots, 29] be an array storing 30 distinct integers in descending order. The number of swap operations that will be performed, if the function fun() is called with A[0,…,29]A[0, \dots, 29] as argument, is __________. (Answer in integer)
Show answer without attempting

Answer: 435

Q65

GATE CS 2025 CS-1Searching Sorting and HashingNAT2 marks
In a double hashing scheme, h1(k)=k mod 11h_1(k) = k \bmod 11 and h2(k)=1+(k mod 7)h_2(k) = 1 + (k \bmod 7) are the auxiliary hash functions. The size mm of the hash table is 11. The hash function for the i-th probe in the open address table is [h1(k)+i h2(k)] mod m[h_1(k) + i \, h_2(k)] \bmod m. The following keys are inserted in the given order: 63, 50, 25, 79, 67, 24.
The slot at which key 24 gets stored is ___________. (Answer in integer)
Show answer without attempting

Answer: 10 to 11

Q20

GATE CS 2025 CS-2Searching Sorting and HashingMCQ1 mark−1/3 if wrong
Consider an unordered list of NN distinct integers.

What is the minimum number of element comparisons required to find an integer in the list that is NOT the largest in the list?
Show answer without attempting

Answer: A

Q20

GATE CS 2023 CSSearching Sorting and HashingMCQ1 mark−1/3 if wrong
An algorithm has to store several keys generated by an adversary in a hash table. The adversary is malicious who tries to maximize the number of collisions. Let kk be the number of keys, mm be the number of slots in the hash table, and k>mk > m.

Which one of the following is the best hashing strategy to counteract the adversary?
Show answer without attempting

Answer: C

Q16

GATE CS 2022 CSSearching Sorting and HashingMCQ1 mark−1/3 if wrong
Suppose we are given nn keys, mm hash table slots, and two simple uniform hash functions h1h_1 and h2h_2. Further suppose our hashing scheme uses h1h_1 for the odd keys and h2h_2 for the even keys. What is the expected number of keys in a slot?
Show answer without attempting

Answer: B

Q2

GATE CS 2021 CS-1Searching Sorting and HashingMCQ1 mark−1/3 if wrong
Let P be an array containing nn integers. Let tt 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 nn elements. Which one of the following choices is correct?
Show answer without attempting

Answer: C

Q9

GATE CS 2021 CS-1Searching Sorting and HashingMCQ1 mark−1/3 if wrong
Consider the following array.
2332456972738997
Which algorithm out of the following options uses the least number of comparisons (among the array elements) to sort the above array in ascending order?
Show answer without attempting

Answer: C

Q47

GATE CS 2021 CS-1Searching Sorting and HashingMSQ2 marks
Consider a dynamic hashing approach for 4-bit integer keys:
1. There is a main hash table of size 4.
2. The 2 least significant bits of a key is used to index into the main hash table.
3. Initially, the main hash table entries are empty.
4. Thereafter, when more keys are hashed into it, to resolve collisions, the set of all keys corresponding to a main hash table entry is organized as a binary tree that grows on demand.
5. First, the 3rd least significant bit is used to divide the keys into left and right subtrees.
6. To resolve more collisions, each node of the binary tree is further sub-divided into left and right subtrees based on the 4th least significant bit.
7. A split is done only if it is needed, i.e., only when there is a collision.
Consider the following state of the hash table.
Which of the following sequences of key insertions can cause the above state of the hash table (assume the keys are in decimal notation)?
Question figure
More than one option can be correct.
Show answer without attempting

Answer: C

Q23

GATE CS 2020 CSSearching Sorting and HashingNAT1 mark
Consider a double hashing scheme in which the primary hash function is h1(k)=k mod 23h_1(k) = k \bmod 23, and the secondary hash function is h2(k)=1+(k mod 19)h_2(k) = 1 + (k \bmod 19). Assume that the table size is 23. Then the address returned by probe 1 in the probe sequence (assume that the probe sequence begins at probe 0) for key value k=90k = 90 is __________.
Show answer without attempting

Answer: 13

Q37

GATE CS 2019 CSSearching Sorting and HashingMCQ2 marks−2/3 if wrong
There are nn unsorted arrays: A1,A2,...,AnA_1, A_2, ..., A_n. Assume that nn is odd. Each of A1,A2,...,AnA_1, A_2, ..., A_n contains nn distinct elements. There are no common elements between any two arrays. The worst-case time complexity of computing the median of the medians of A1,A2,...,AnA_1, A_2, ..., A_n is
Show answer without attempting

Answer: C

Q48

GATE CS 2017 CS-1Searching Sorting and HashingNAT2 marks
Let AA be an array of 3131 numbers consisting of a sequence of 00's followed by a sequence of 11's. The problem is to find the smallest index ii such that A[i]A[i] is 11 by probing the minimum number of locations in AA. The worst case number of probes performed by an optimal algorithm is ____________.
Show answer without attempting

Answer: 5.0

Q43

GATE CS 2017 CS-2Searching Sorting and HashingNAT2 marks
Consider the following snippet of a C program. Assume that swap(&x, &y) exchanges the contents of xx and yy.
int main() {
    int array[] = {3, 5, 1, 4, 6, 2};
    int done = 0;
    int i;
    while (done == 0) {
        done = 1;
        for (i=0; i<=4; i++) {
            if (array[i] < array[i+1]) {
                swap(&array[i], &array[i+1]);
                done = 0;
            }
        }
        for (i=5; i>=1; i--) {
            if (array[i] > array[i-1]) {
                swap(&array[i], &array[i-1]);
                done = 0;
            }
        }
    }
    printf("%d", array[3]);
}
The output of the program is ____________.
Show answer without attempting

Answer: 3.0

Q13

GATE CS 2016 CS-1Searching Sorting and HashingMCQ1 mark−1/3 if wrong
The worst case running times of Insertion sort, Merge sort and Quick sort, respectively, are:
Show answer without attempting

Answer: D

Q13

GATE CS 2016 CS-2Searching Sorting and HashingMCQ1 mark−1/3 if wrong
Assume that the algorithms considered here sort the input sequences in ascending order. If the input is already in ascending order, which of the following are TRUE?

I. Quicksort runs in Θ(n2)\Theta(n^2) time
II. Bubblesort runs in Θ(n2)\Theta(n^2) time
III. Mergesort runs in Θ(n)\Theta(n) time
IV. Insertion sort runs in Θ(n)\Theta(n) time
Show answer without attempting

Answer: D

Q22

GATE CS 2015 CS-3Searching Sorting and HashingNAT1 mark
Given a hash table TT with 25 slots that stores 2000 elements, the load factor α\alpha for TT is ____________.
Show answer without attempting

Answer: 80

Q50

GATE CS 2015 CS-2Searching Sorting and HashingMCQ2 marks−2/3 if wrong
Which one of the following hash functions on integers will distribute keys most uniformly over 10 buckets numbered 0 to 9 for ii ranging from 0 to 2020?
Show answer without attempting

Answer: B

Q14

GATE CS 2014 CS-3Searching Sorting and HashingMCQ1 mark−1/3 if wrong
You have an array of nn elements. Suppose you implement quicksort by always choosing the central element of the array as the pivot. Then the tightest upper bound for the worst case performance is
Show answer without attempting

Answer: A

0/200 correct0 marks

Related topics in Algorithms