Skip to content

GATE CS Searching, Sorting, Hashing questions

Practise Searching, Sorting, Hashing questions for GATE CS. Explore official PYQs and original topic-wise quizzes, check answers and view available solutions. Free, no sign-in.

Subject, topic, year and type filter the full library. Match any choice within a filter, and all selected filter categories. Search, source and sort apply to this page.

20 on this page
Official PYQ2026AlgorithmsSearching, Sorting, HashingMSQ · 1 mark
Let nn be an odd number greater than 100100. Consider a binary minheap with nn elements stored in an array PP whose index starts from 11. Which of the following indices of PP do/does NOT correspond to any leaf node of the minheap?
Official PYQ2026AlgorithmsSearching, Sorting, HashingMCQ · 1 mark
Consider a hash table P[0,1,…,10]P[0,1, \ldots, 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 11h(x)=(x+7) \bmod 11. Consider the following sequence of insertions performed on PP :  1,13, 22, 15, 11, 24\text{ 1,13, 22, 15, 11, } 24 Which of the following positions in the hash table is/are empty …
Official PYQ2026AlgorithmsSearching, Sorting, HashingNAT · 1 mark
The height of a binary tree is the number of edges in the longest path from the root to a leaf in the tree. The maximum possible height of a full binary tree with 2323 nodes is ____\_\_\_\_.(answer in integer)
Official PYQ2026AlgorithmsSearching, Sorting, HashingMCQ · 2 marks
Let PP be the set of all integers from 11 to 1515. Consider any order of insertion of the elements of PP into a binary search tree that creates a complete binary tree. Which one of the following elements can NEVER be the third element that is inserted?
Official PYQ2026AlgorithmsSearching, Sorting, HashingNAT · 2 marks
The following sequence corresponds to the preorder traversal of a binary search tree TT : 50,25,13,40,30,47,75,60,70,80,7750,25,13,40,30,47,75,60,70,80,77 The position of the element 6060 in the postorder traversal of TT is ____\_\_\_\_ . (answer in integer) Note: The position begins with 11.
Official PYQ2026AlgorithmsSearching, Sorting, HashingNAT · 1 mark
The keys 5,28,19,15,26,33,12,17,105,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)
Official PYQ2026AlgorithmsSearching, Sorting, HashingNAT · 1 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 77 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 …
Official PYQ2026AlgorithmsSearching, Sorting, HashingMSQ · 2 marks
Consider a binary search tree (BST) with nn leaf nodes (n>0)(n>0). Given any node VV, the key present in the node is denoted as Val⁡(V)\operatorname{Val}(V). All the keys present in the given BST are distinct. The keys belong to the set of real numbers. For a node VV, let Suc⁡(V)\operatorname{Suc}(V) denote the node that is its inorder successor. If a …
Official PYQ2025AlgorithmsSearching, Sorting, HashingNAT · 1 mark
The pseudocode of a function fun ()\text{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]A[0, \ldots, 29] be an array storing 3030 distinct integers in descending order. The number of swap operations that will be performed, if the function fun ()\text{fun ()} is called …
Official PYQ2025AlgorithmsSearching, Sorting, HashingNAT · 2 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 1111. The hash function for the ii-th probe in the open address table is [h1(k)+ih2(k)] mod m\left[h_{1}(k)+i h_{2}(k)\right] \bmod m. The following keys are inserted in the given order: 63,50,25,79,67,2463,50,25,79,67,24. The slot …
Official PYQ2025AlgorithmsSearching, Sorting, HashingMCQ · 1 mark
​​​​Consider an unorders list of NN distinct integers. What is the minimum number of element comaparisons required to find an integer in the list that is NOT the largest in the list?
Official PYQ2025AlgorithmsSearching, Sorting, HashingMCQ · 2 marks
​​An array AA of length nn with distinct elements is said to be bitonic if there is an index 1≤i≤n1 \leq i \leq n such that A[1..i]A[1 . . i] is sorted in the non-decreasing order and A[i+1…n]A[i+1 \ldots 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 …
Official PYQ2024AlgorithmsSearching, Sorting, HashingMCQ · 2 marks
​​​​​An array [82,101,90,11,111,75,33,131,44,93][82,101,90,11,111,75,33,131,44,93] is heapified. Which one of the following options represents the first three elements in the heapified array?
Official PYQ2024AlgorithmsSearching, Sorting, HashingNAT · 1 mark
Let A\text{A} be an array containing integer values. The distance of A\text{A} is defined as the minimum number of elements in A\text{A} that must be replaced with another integer so that the resulting array is sorted in non-decreasing order. The distance of the array [2,5,3,1,4,2,6][2,5,3,1,4,2,6] is ___________.
Official PYQ2023AlgorithmsSearching, Sorting, HashingMCQ · 1 mark
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?
Official PYQ2022AlgorithmsSearching, Sorting, HashingMCQ · 1 mark
​​​Suppose we are given nn keys, mm hash table slots, and two simple uniform hash functions h1h_{1} and h2.h_{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?
Official PYQ2021AlgorithmsSearching, Sorting, HashingMCQ · 1 mark
Consider the following array.2332456972738997\begin{array}{|l|l|l|l|l|l|} \hline 23&32&45&69&72&73&89&97 \\ \hline\end{array} 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?
Official PYQ2021AlgorithmsSearching, Sorting, HashingMCQ · 2 marks
Consider a dynamic\textit{dynamic} hashing approach for 44-bit integer keys: There is a main hash table of size 44. The 22 least significant bits of a key is used to index into the main hash table. Initially, the main hash table entries are empty. Thereafter, when more keys are hashed into it, to resolve collisions, the set of all keys corresponding to …
Official PYQ2021AlgorithmsSearching, Sorting, HashingMCQ · 1 mark
What is the worst-case number of arithmetic operations performed by recursive binary search on a sorted array of size nn?
Official PYQ2020AlgorithmsSearching, Sorting, HashingNAT · 1 mark
Consider a double hashing scheme in which the primary hash function is h1(k)=k mod 23h_1(k)= k \text{ mod } 23, and the secondary hash function is h2(k)=1+(k mod 19)h_2(k)=1+(k \text{ mod } 19). Assume that the table size is 2323. Then the address returned by probe 11 in the probe sequence (assume that the probe sequence begins at probe 00) for key value k=90k=90 …