GateAI

GATE CSE Sorting PYQs

Standard yield1.6% of Algorithms

In this topic, GATE tests the performance characteristics and comparison counts of classic sorting algorithms under specific input configurations (such as alrea… Read the guide

Questions
3
Asked
since 2015
Total marks
3
Marks / paper
0.1

3 GATE CSE Sorting PYQs with solutions, from Algorithms. Browse all GATE CSE PYQs.

What GATE tests in Sorting

Concepts, patterns, formulas and traps distilled from past papers.

In this topic, GATE tests the performance characteristics and comparison counts of classic sorting algorithms under specific input configurations (such as already sorted arrays). Questions focus on identifying best-case vs. worst-case behaviors, comparison complexity bounds, and algorithm-specific adaptability.

Core concepts

  • Merge Sort worst-case time complexity O(n log n) and execution time scaling
  • Bubble Sort loop bounds and conditional swap execution
  • Worst-case descending order input and inversion counting
  • Best-case and worst-case comparison complexity of Insertion Sort
  • Data-insensitivity of Selection Sort comparisons
  • Quicksort worst-case behavior under sorted input and deterministic pivot choice
  • Mergesort comparison bounds (O(n log n))

Recurring question patterns

  • Time-Scaling Proportionality Calculation

    OccasionalMCQ1 marks2015

    Given the execution time of a comparison-based sort (like Merge Sort) for a specific input size n1n_1, calculate the maximum input size n2n_2 solvable within an expanded time limit assuming T(n)=c⋅f(n)T(n) = c \cdot f(n).

  • Pseudocode Operation Counting

    OccasionalNAT1 marks2025

    Given a sorting loop structure (such as nested loops of Bubble Sort) and a specific input configuration (such as reverse sorted array), calculate the exact number of key operations (comparisons or swaps) executed.

  • Comparison Count on Specific Input Presets

    CommonMCQ1 marks2021

    An input array with specific properties (e.g., pre-sorted array) is provided, and the candidate must evaluate which sorting algorithm performs the minimum or maximum number of element comparisons.

Formulas GATE uses

Merge Sort Running Time Relation

T(n)=c⋅nlog⁡2nT(n) = c \cdot n \log_2 n

Used to compute scaling factor cc and solve for target problem size nn given execution time.

Worst-case Bubble Sort Swaps (Inversion Count)

∑i=0n−2(n−1−i)=n(n−1)2\sum_{i=0}^{n-2} (n - 1 - i) = \frac{n(n - 1)}{2}

Used to calculate the exact number of swap operations performed by standard bubble sort on a strictly decreasing array of size nn.

Insertion Sort Best-Case Comparisons

Cbest=n−1C_{\text{best}} = n - 1

Calculated when the input array is already sorted in ascending order.

Selection Sort Total Comparisons

C=n(n−1)2C = \frac{n(n-1)}{2}

Evaluated for Selection Sort regardless of input order as it always scans the remaining unsorted subarray.

Quicksort Worst-Case Comparisons (End Pivot on Sorted Array)

Cworst=n(n−1)2C_{\text{worst}} = \frac{n(n-1)}{2}

Evaluated when an already sorted array is partitioned using the first or last element as the pivot.

Examiner traps in Sorting

  • Unit conversion errors between seconds and minutes when computing time bounds (e.g., forgetting to convert 6 minutes to 360 seconds).
  • Off-by-one errors in nested loop iteration counts (e.g., using n(n+1)/2 instead of n(n-1)/2).
  • Assuming base-10 instead of base-2 for log n when evaluating powers-of-two input sizes.
  • Failing to inspect the input array to notice that it is already sorted in non-decreasing order.
  • Confusing Quicksort's best-case and worst-case behaviors, particularly assuming Quicksort always takes O(n log n) comparisons regardless of pivot selection strategy.
  • Assuming Selection Sort optimizes comparisons when the array is already sorted.

How questions are asked

  • Proportionality time-limit calculation
  • Pseudocode tracing and exact operation counting
  • Identifying the sorting algorithm with minimal comparisons for a given array

Paper trends

  • Shift from multiple-choice questions on asymptotic scaling ratios to numerical answer type (NAT) questions assessing exact step counts on standard sorting pseudocode.

    2025, 2015

  • Questions test fundamental behavior by presenting an explicit array to verify whether candidates recognize pre-sorted inputs and map them to the best-case time and comparison complexity of standard algorithms.

    2021

Difficulty notes

Easy questions require standard formula application such as n(n−1)/2n(n-1)/2 for loop bounds on an array of size nn. Medium questions involve multi-step arithmetic where constants must be resolved and non-linear equations (like nlog⁡2n=Kn \log_2 n = K) matched against power-of-two choices.