Skip to content

GATE CS Algorithms questions

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

Compare greedy choices, dynamic-programming states and graph algorithms. Identify the input size before analysing the time and space complexity of each solution.

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 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 PYQ2025AlgorithmsShortest Paths (Dijkstra, Bellman-Ford)MCQ · 2 marks
Let G(V,E)G(V, E) be an undirected and unweighted graph with 100100 vertices. Let d(u,v)d(u, v) denote the number of edges in a shortest path between vertices uu and vv in VV. Let the maximum value of d(u,v),u,v∈Vd(u, v), u, v \in V such that u≠vu \neq v, be 3030. Let TT be any breadth-first-search tree of GG. Which ONE of the given options is CORRECT …
Official PYQ2025AlgorithmsMinimum Spanning TreesNAT · 2 marks
The maximum value of x\text{x} such that the edge between the nodes B\text{B} and C\text{C} is included in every minimum spanning tree of the given graph is _________. (answer in integer)
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 PYQ2025AlgorithmsGraph Traversals (BFS, DFS)NAT · 2 marks
Consider the following algorithm someAlgo that takes an undirected graph GG as input. someAlgo (G) Let vv be any vertex in GG. Run BFS on GG starting at vv. Let uu be a vertex in GG at maximum distance from vv as given by the BFS. Run BFS on GG again with uu as the starting vertex. Let zz be the vertex at maximum distance …
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 PYQ2025AlgorithmsGraph Traversals (BFS, DFS)MSQ · 1 mark
​​​​Which of the following statements regarding Breadth First Search (BFS) and Depth First Search (DFS) on an undirected simple graph GG is/are TRUE?
Official PYQ2025AlgorithmsMinimum Spanning TreesMCQ · 2 marks
​​​​Let G\text{G} be an edge-weighted undirected graph with positive edge weights. Suppose a positive constant α\alpha is added to the weight of every edge. Which ONE of the following statements is TRUE about the minimum spanning trees (MSTs) and shortest paths (SPs) in G\text{G} before and after the edge weight update?
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 PYQ2024AlgorithmsAsymptotic Worst Case Time and Space ComplexityMCQ · 1 mark
Given an integer array of size NN, we want to check if the array is sorted (in either ascending or descending order). An algorithm solves this problem by making a single pass through the array and comparing each element of the array only with its adjacent elements. The worst-case time complexity of this algorithm is
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 PYQ2024AlgorithmsAsymptotic Worst Case Time and Space ComplexityMCQ · 2 marks
Consider the following recurrence relation: T(n)={nT(n)+n for n≥1,1 for n=1T(n)=\left\{\begin{array}{c}\sqrt{n} T(\sqrt{n})+n \text{ for } n \geq 1, \\ 1 \quad \text{ for } n=1\end{array}\right. Which one of the following options is CORRECT?
Official PYQ2024AlgorithmsGraph Traversals (BFS, DFS)MCQ · 2 marks
​​​​Let GG be a directed graph and TT a depth first search (DFS)\text{(DFS)} spanning tree in GG that is rooted at a vertex vv. Suppose TT is also a breadth first search (BFS)\text{(BFS)} tree in GG, rooted at vv. Which of the following statements is/are TRUE for every such graph GG and tree TT?
Official PYQ2024AlgorithmsGraph Traversals (BFS, DFS)NAT · 2 marks
The number of edges present in the forest generated by the DFS\text{DFS} traversal of an undirected graph GG with 100100 vertices is 4040. The number of connected components in GG is __________.
Official PYQ2024AlgorithmsAsymptotic Worst Case Time and Space ComplexityMCQ · 1 mark
​​​​​Let T(n)\text{T(n)} be the recurrence relation defined as follows: T(0)=1,T(1)=2, and T(n)=5T(n−1)−6T(n−2) for n≥2\begin{array}{l} T(0)=1, \\ T(1)=2, \text{ and } \\ T(n)=5 T(n-1)-6 T(n-2) \text{ for } n \geq 2 \end{array} Which one of the following statements is TRUE?
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 PYQ2024AlgorithmsAlgorithm Design: Greedy TechniquesMCQ · 2 marks
​​​​Consider an array X\mathrm{X} that contains n\mathrm{n} positive integers. A subarray of X\mathrm{X} is defined to be a sequence of array locations with consecutive indices. The C\mathrm{C} code snippet given below has been written to compute the length of the longest subarray of X\mathrm{X} that contains at most two distinct integers. The …
Official PYQ2024AlgorithmsMinimum Spanning TreesNAT · 2 marks
The number of distinct minimum-weight spanning trees of the following graph 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 PYQ2023AlgorithmsAsymptotic Worst Case Time and Space ComplexityMSQ · 1 mark
Let ff and gg be functions of natural numbers given by f(n)=nf(n)=n and g(n)=n2.g(n)=n^{2}. Which of the following statements is/are TRUE?\text{TRUE}?