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
Let be an odd number greater than . Consider a binary minheap with elements stored in an array whose index starts from . Which of the following indices of do/does NOT correspond to any leaf node of the minheap?
Consider a hash table that is initially empty. The hash table is maintained using open addressing with linear probing. The hash function used is . Consider the following sequence of insertions performed on : Which of the following positions in the hash table is/are empty …
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 nodes is .(answer in integer)
Let be the set of all integers from to . Consider any order of insertion of the elements of 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?
The following sequence corresponds to the preorder traversal of a binary search tree : The position of the element in the postorder traversal of is . (answer in integer) Note: The position begins with .
The keys are inserted into a hash table using the hash function . The collisions are resolved by chaining. After all the keys are inserted, the length of the longest chain is . (answer in integer)
Consider an array . Suppose the merge sort algorithm is executed on array to sort it in increasing order. The merge sort algorithm will carry out a total of merge operations. A merge operation on sorted left array and sorted right array is said to be void if the output of the merge operation is the …
Consider a binary search tree (BST) with leaf nodes . Given any node , the key present in the node is denoted as . All the keys present in the given BST are distinct. The keys belong to the set of real numbers. For a node , let denote the node that is its inorder successor. If a …
The pseudocode of a function 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 be an array storing distinct integers in descending order. The number of swap operations that will be performed, if the function is called …
In a double hashing scheme, and are the auxiliary hash functions. The size of the hash table is . The hash function for the -th probe in the open address table is . The following keys are inserted in the given order: . The slot …
Consider an unorders list of 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?
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 …
An array is heapified. Which one of the following options represents the first three elements in the heapified array?
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 ___________.
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 be the number of keys, be the number of slots in the hash table, and . Which one of the following is the best hashing strategy to counteract the adversary?
Suppose we are given keys, hash table slots, and two simple uniform hash functions and Further suppose our hashing scheme uses for the odd keys and for the even keys. What is the expected number of keys in a slot?
Consider the following 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?
Consider a hashing approach for -bit integer keys: There is a main hash table of size . The 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 …
What is the worst-case number of arithmetic operations performed by recursive binary search on a sorted array of size ?
Consider a double hashing scheme in which the primary hash function is , and the secondary hash function is . Assume that the table size is . Then the address returned by probe in the probe sequence (assume that the probe sequence begins at probe ) for key value …
