GATE CSE Searching, Sorting and Hashing PYQs
Across GATE CS exams, Searching, Sorting, and Hashing are tested with a strong emphasis on exact comparison/swap counts, worst/best-case edge cases (especially… Read the guide
- Questions
- 27
- Asked
- since 2012
- Total marks
- 39
- Marks / paper
- 1.6
27 GATE CSE Searching, Sorting and Hashing PYQs with solutions, from Algorithms. Browse all GATE CSE PYQs.
Questions
Every official paper that asked this topic, newest first.
- GATE CSE 2026 Set 1 · Q24Consider 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…MSQ1 markEasySolve
- GATE CSE 2026 Set 2 · Q30The keys 5, 28, 19, 15, 26, 33, 12, 17, 10 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)NAT1 markEasySolve
- GATE CSE 2026 Set 2 · Q32Consider 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 7 merge operations. A merge operation on sorted left array and sorted right array is said to be void if…NAT1 markMediumSolve
- GATE CSE 2025 Set 1 · Q65In a double hashing scheme, and are the auxiliary hash functions. The size of the hash table is 11. The hash function for the -th probe in the open address table is . The following keys are inserted in the given order: 63,…NAT2 marksMediumSolve
- GATE CSE 2025 Set 2 · Q41An 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…MCQ2 marksMediumSolve
- GATE CSE 2023 · Q20An 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…MCQ1 markEasySolve
- GATE CSE 2022 · Q16Suppose 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?MCQ1 markEasySolve
- GATE CSE 2021 Set 1 · Q2Let P be an array containing integers. Let 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 elements. Which one of the following choices is correct?MCQ1 markMediumSolve
- GATE CSE 2021 Set 1 · Q47Consider 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…MSQ2 marksMediumDiagramSolve
- GATE CSE 2021 Set 2 · Q8What is the worst-case number of arithmetic operations performed by recursive binary search on a sorted array of size ?MCQ1 markEasySolve
- GATE CSE 2020 · Q23Consider a double hashing scheme in which the primary hash function is , and the secondary hash function is . 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…NAT1 markEasySolve
- GATE CSE 2019 · Q20An array of 25 distinct elements is to be sorted using quicksort. Assume that the pivot element is chosen uniformly at random. The probability that the pivot element gets placed in the worst possible location in the first round of partitioning (rounded off to 2 decimal places) is _______.NAT1 markEasySolve
- GATE CSE 2017 Set 1 · Q48Let be an array of 31 numbers consisting of a sequence of 0's followed by a sequence of 1's. The problem is to find the smallest index such that is 1 by probing the minimum number of locations in . The worst case number of probes performed by an optimal algorithm is ________.NAT2 marksMediumSolve
- GATE CSE 2016 Set 1 · Q13The worst case running times of Insertion sort, Merge sort and Quick sort, respectively, are:MCQ1 markEasySolve
- GATE CSE 2016 Set 2 · Q13Assume 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 time II. Bubblesort runs in time III. Mergesort runs in time IV. Insertion sort runs…MCQ1 markMediumSolve
- GATE CSE 2015 Set 1 · Q40An algorithm performs find operations, insert operations, delete operations, and decrease-key operations on a set of data items with keys drawn from a linearly ordered set. For a delete operation, a pointer is provided to the record that must be deleted.…MCQ2 marksMediumSolve
- GATE CSE 2015 Set 3 · Q17Given a hash table with 25 slots that stores 2000 elements, the load factor for is _______.NAT1 markEasySolve
- GATE CSE 2014 Set 1 · Q14Let be a quicksort program to sort numbers in ascending order using the first element as the pivot. Let and be the number of comparisons made by for the inputs [1 2 3 4 5] and [4 1 5 3 2] respectively. Which one of the following holds?MCQ1 markMediumSolve
- GATE CSE 2014 Set 1 · Q39The minimum number of comparisons required to find the minimum and the maximum of 100 numbers is _________.NAT2 marksEasySolve
- GATE CSE 2014 Set 1 · Q40Consider a hash table with 9 slots. The hash function is . The collisions are resolved by chaining. The following 9 keys are inserted in the order: 5, 28, 19, 15, 20, 33, 12, 17, 10. The maximum, minimum, and average chain lengths in the hash table, respectively, areMCQ2 marksEasySolve
- GATE CSE 2014 Set 2 · Q38Suppose P, Q, R, S, T are sorted sequences having lengths 20, 24, 30, 35, 50 respectively. They are to be merged into a single sequence by merging together two sequences at a time. The number of comparisons that will be needed in the worst case by the optimal algorithm for doing this is .NAT2 marksMediumSolve
- GATE CSE 2014 Set 3 · Q14You have an array of 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 isMCQ1 markEasySolve
- GATE CSE 2014 Set 3 · Q38Consider the decision problem defined as follows: is a satisfiable propositional formula in CNF with at most two literals per clause For example, is a Boolean formula and it is in . The…MCQ2 marksMediumSolve
- GATE CSE 2014 Set 3 · Q40Consider a hash table with 100 slots. Collisions are resolved using chaining. Assuming simple uniform hashing, what is the probability that the first 3 slots are unfilled after the first 3 insertions?MCQ2 marksEasySolve
- GATE CSE 2013 · Q6Which one of the following is the tightest upper bound that represents the number of swaps required to sort numbers using selection sort?MCQ1 markEasySolve
- GATE CSE 2013 · Q30The number of elements that can be sorted in time using heap sort isMCQ2 marksMediumSolve
- GATE CSE 2012 · Q39A list of strings, each of length , is sorted into lexicographic order using the merge-sort algorithm. The worst case running time of this computation isMCQ2 marksMediumSolve
What GATE tests in Searching, Sorting and Hashing
Concepts, patterns, formulas and traps distilled from past papers.
Across GATE CS exams, Searching, Sorting, and Hashing are tested with a strong emphasis on exact comparison/swap counts, worst/best-case edge cases (especially for Quicksort and simultaneous min-max finding), trace-based simulation (such as step-by-step hashing probes and merge passes), and asymptotic tradeoffs for specialized or composite data inputs. Questions range from conceptual 1-mark classification to rigorous 2-mark NATs requiring precise manual execution of collision resolution or optimal merge trees.
Core concepts
- Quicksort partition mechanics and worst-case permutations under various pivot rules
- Pairwise simultaneous minimum and maximum finding algorithm
- Optimal merge pattern using min-heap / greedy strategy
- Chaining vs. Open Addressing (Linear Probing, Quadratic Probing, Double Hashing)
- Hash table load factor and chain length distributions
- Binary search modifications (bitonic peak finding and partitioned binary search)
- Comparison cost on complex keys (e.g., variable or length-n strings)
- Elementary sorting bounds (Selection sort swaps O(n), Insertion sort best case O(n))
- Simple Uniform Hashing Assumption (SUHA) and independence of keys
- Linear probing collision resolution and cyclic wrap-around
- Double hashing probe formulas and non-zero step sizes (h2(k) 0)
- Expected chain length / load factor = n/m
- Universal hashing vs. deterministic hash functions against adversaries
- Probability calculations on slot occupancy
- Worst-case asymptotic running times of Insertion sort, Merge sort, and Quick sort
- Decision tree lower bounds and information-theoretic probe limits
- Binary search recurrence relations and arithmetic operation counting
- Monotone array transition point search
Recurring question patterns
Simultaneous Min-Max Comparison Counting
Commonmixed2 marks2021, 2014Determining the exact minimum comparisons or bounding intervals required to find both the minimum and maximum elements in an array of size using pairwise grouping.
Hash Table Collision Resolution Trace & Metric Computation
Commonmixed1.5 marks2026, 2025, 2021, 2015Tracing the insertion of given integer keys into a hash table using chaining, dynamic bitwise trees, or open addressing (linear, quadratic, or double hashing) to find slot positions, chain lengths, or load factor .
Quicksort Pivot Selection & Partition Behavior
Commonmixed1 marks2019, 2016, 2014Analyzing comparisons, worst-case recurrences, or probability of bad partitions under various pivot selection rules (first element, central element, or uniformly random pivot) on specific input permutations.
Merge Sort Traces and Multi-way/Optimal Merging
CommonNAT1.5 marks2026, 2014Calculating exact comparison counts using Huffman-like greedy 2-way merging (Optimal Merge Pattern) or step-by-step tracing of recursion trees and specific merge predicates (e.g., void merges).
Search/Sort Variations on Non-standard Inputs
OccasionalMCQ2 marks2025, 2013, 2012Evaluating asymptotic bounds for searching in specialized structured arrays (e.g., bitonic arrays), sorting compound items (e.g., strings of length ), or inverse-solving element counts for fixed asymptotic time targets.
Operation-Frequency-Driven Data Structure Selection
RareMCQ2 marks2015Choosing the data structure (unsorted array, min-heap, balanced BST) that minimizes total asymptotic time given a specific non-uniform frequency mix of operations.
Open Addressing Probe Address Calculation
CommonNAT1 marks2020Given hash functions (e.g., and ) and a table size , calculate the exact slot index inspected at a specific probe number for a given key in open addressing schemes like double hashing or linear probing.
Hash Table Insertion Tracing & Occupancy
CommonMSQ1 marks2026Given an initial empty table and a sequence of keys with a specified collision resolution method (e.g., linear probing with wrap-around modulo arithmetic), trace step-by-step insertions to identify occupied or unoccupied slot indices.
Probability and Expectation under SUHA
CommonMCQ1.5 marks2022, 2014Evaluate the probability of specific slot configurations (e.g., specific slots remaining empty after multiple insertions) or calculate expected slot chain lengths / expected keys per slot using linearity of expectation under simple uniform hashing assumptions.
Theoretical Concepts & Adversarial Collision Resistance
OccasionalMCQ1 marks2023Test understanding of hash function properties, limitations of deterministic hashing (division/multiplication methods) against worst-case adversaries, and the role of universal hashing in achieving expected performance.
Standard Algorithm Worst-Case Comparison
CommonMCQ1 marks2016Matching or listing the tight asymptotic worst-case time complexities of classical sorting algorithms like Insertion sort, Merge sort, and Quick sort.
Binary Search Decision Tree and Worst-Case Probe Count
OccasionalNAT2 marks2017Determining the exact minimum number of worst-case probes required by an optimal algorithm to locate a boundary or transition point in a sorted/monotone array of fixed size .
Recurrence and Operation Count for Recursive Searching
CommonMCQ1 marks2021Identifying the asymptotic bound on the number of arithmetic/comparison operations executed during recursive binary search.
Formulas GATE uses
Simultaneous Min and Max Comparisons (Even $n$)
Used when finding both minimum and maximum of an even number of elements with minimum comparisons by pairwise grouping.
Simultaneous Min and Max Comparisons (Odd $n$)
Used when calculating optimal min-max comparisons for an odd number of elements.
Worst-case 2-Way Merge Comparisons
Used during each step of the optimal merge pattern when combining two sorted arrays of sizes and .
Load Factor of Hash Table
Used to compute average items per slot where is the number of keys and is the number of slots.
Double Hashing Probe Sequence
Used to determine the -th probe slot for key in open addressing double hashing.
Worst-case Quicksort Pivot Probability
Used for uniform random pivot selection on distinct elements where minimum and maximum elements yield the most unbalanced split.
Linear Probing Probe Sequence
Used when iteratively resolving collisions by inspecting consecutive cyclic slots.
Expected Slot Occupancy (Load Factor under SUHA)
Used to find the expected number of keys hashing to any specific slot when independent keys are hashed across slots.
Independent Slot Avoidance Probability
Used under SUHA when independent keys must hash exclusively outside a designated subset of slots.
Binary Search Worst-Case Probe Bound
Used to find the minimum number of probes required in the worst case to determine the exact transition index in a sequence of elements with possible outcome states.
Recursive Binary Search Recurrence
Used when analyzing the number of operations or recursive steps executed by binary search on an array of size .
Worst-Case Unbalanced Quick Sort Recurrence
Used to evaluate the worst-case running time of Quick sort under extreme unbalanced pivot partitions.
Examiner traps in Searching, Sorting and Hashing
- Assuming picking the central or median-of-three pivot prevents worst-case (n2) behavior on all inputs (adversarial inputs still exist).
- Forgetting the -1 in pairwise array merging: merging lengths m and n costs at most m + n - 1 comparisons, not m + n.
- Mixing 0-indexed and 1-indexed hash tables during open addressing double hashing calculations.
- Applying O(n log n) string merge sort without multiplying by the O(n) string comparison cost.
- Forgetting that early-exit Bubblesort and standard Insertion sort take (n) time on already sorted inputs, while Merge sort remains (n log n).
- Zero-based vs one-based probe indexing: confusing probe 0 (initial hash) with probe 1 (first collision resolution step).
- Modulo wrap-around omission: forgetting to apply mod m when linear or double probing wraps past the end of the table array.
- Dependent vs independent probability errors: treating independent random hashing of keys as non-replacement sampling (m-1, m-2 vs constant m-s choices).
- Assuming partitioned hash functions alter expected load: partitioning keys between two distinct SUHA functions still yields n/m total expected keys per slot.
- Confusing average-case time (n log n) of Quick sort with its worst-case time (n2)
- Off-by-one errors when counting possible outcomes for binary search (e.g., using ⌈ log2(n) ⌉ instead of ⌈ log2(n+1) ⌉ when an element can also be absent or occur at position n+1)
- Confusing the number of recursive stack frames/operations with linear traversal when array slicing or mid-point arithmetic is involved
How questions are asked
- Trace and find the target slot in double hashing / open addressing
- Calculate exact number of comparisons for simultaneous min-max or optimal merge
- Count occurrences of a specific merge condition (e.g., void merges) during standard algorithm execution
- Calculate chain metrics (maximum, minimum, average chain lengths) under modular hashing
- Asymptotic complexity analysis with specialized data sizes or non-standard operation counts
- Probability calculation for pivot placement under randomized algorithms
- Probe address computation (evaluate h(k, i) numerically)
- Insertion trace to identify empty/occupied table slots
- Probability computation under Simple Uniform Hashing Assumption
- Conceptual selection of hashing scheme against adversarial collision
- Multi-algorithm complexity matching list (MCQ)
- Exact worst-case probe calculation for array search (NAT)
- Asymptotic operation count for recursive divide-and-conquer routines (MCQ)
Paper trends
Shift from standard Big-O identification of basic sorting algorithms towards exact manual tracing (e.g., counting void merges, computing exact probe index in double hashing).
2026, 2025
Increased usage of NAT question formats for hashing and merge computations rather than multiple-choice options.
2026, 2025, 2019, 2015, 2014
Inclusion of non-standard hashing mechanisms, such as MSQs testing trie-like dynamic bit-sliced collision resolution.
2021
Shift from purely single-choice probability or theory questions to procedural tracing and formula evaluation tested via NAT and MSQ formats.
2026, 2020, 2014
Consistent focus on 1-mark foundational conceptual checks, with occasional 2-mark probability/counting questions.
2026, 2023, 2022, 2020, 2014
Direct identification of standard sorting complexities was tested in 1-mark MCQs, while exact decision-tree lower bounds on fixed array sizes appeared as 2-mark NAT questions.
2017, 2016
Questions consistently target divide-and-conquer recurrences ( and ), emphasizing worst-case behavior across recursive search and sort algorithms.
2021, 2016
Difficulty notes
Easy questions test direct definitions (load factor , maximum swaps in selection sort) or single-concept evaluation (chaining max length on <10 keys). Medium questions involve manual tracing (double hashing probe collisions, merge sort execution on 8 elements, optimal merge tree calculation) or multi-step comparison arithmetic ( bounds, bitonic search multi-phase log analysis).