Home › GATE CS › PYQs › Algorithms › Searching, Sorting & Hashing

Searching, Sorting & Hashing — GATE CS Previous Year Questions

Practise GATE CS previous year questions on Searching, Sorting & Hashing in Algorithms. Filter by year, marks and question type.

Public question previews

  • Consider a hash table P[0, 1, … , 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) mod 11. Consider the following sequence of insertions performed on P: 1, 13, 22, 15, 11, 24. Which of the following positions in the hash table is/are empty after these insertions are performed? (2026 · 1 mark · MSQ)
  • 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 9. The collisions are resolved by chaining. After all the keys are inserted, the length of the longest chain is __________. (answer in integer) (2026 · 1 mark · NAT)
  • Consider an array A = [10, 7, 8, 19, 41, 35, 25, 31]. Suppose the merge sort algorithm is executed on array A 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 L and sorted right array R is said to be void if the output of the merge operation is the elements of array L followed by the elements of array R. The number of void merge operations among these 7 merge operations is __________. (answer in integer) (2026 · 1 mark · NAT)
  • The pseudocode of a function fun() is given below: fun(int A[0,…,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] 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] as argument, is __________. (Answer in integer) (2025 · 1 mark · NAT)
  • In a double hashing scheme, h1(k) = k mod 11 and h2(k) = 1 + (k mod 7) are the auxiliary hash functions. The size m 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. 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) (2025 · 2 marks · NAT)