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 PYQ2023AlgorithmsAsymptotic Worst Case Time and Space ComplexityMSQ · 2 marks
Consider functions Function_1\textsf{Function\_1} and Function_2\textsf{Function\_2} expressed in pseudocode as follows: Function_1 while n>1 do for i=1 to n do x = x + 1; end for n = ⌊n/2⌋; end while Function_2 for i = 1 to 100 * n do x = x + 1; end for Let f1(n)f_{1}(n) and f2(n)f_{2}(n) denote the number of times the statement “x = x + 1”\textsf{“x = x + 1”} is executed in …
Official PYQ2023AlgorithmsGraph Traversals (BFS, DFS)NAT · 2 marks
Let U={1,2,3}U=\{1,2,3\}. Let 2U2^{U} denote the powerset of UU. Consider an undirected graph GG whose vertex set is 2U2^{U}. For any A,B∈2U,(A,B)A, B \in 2^{U},(A, B) is an edge in GG if and only if (i) A≠BA \neq B, and (ii) either A⊊BA \subsetneq B or B⊊AB \subsetneq A. For any vertex AA in GG, the set of all possible orderings in which the …
Official PYQ2022AlgorithmsAsymptotic Worst Case Time and Space ComplexityMCQ · 1 mark
Which one of the following statements is TRUE\text{TRUE} for all positive functions f(n)?f(n)?
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 PYQ2022AlgorithmsMinimum Spanning TreesMSQ · 2 marks
Consider a simple undirected weighted graph G,\textit{G}, all of whose edge weights are distinct. Which of the following statements about the minimum spanning trees of G\textit{G} is/are TRUE?\text{TRUE}?
Official PYQ2022AlgorithmsMinimum Spanning TreesNAT · 2 marks
Let G(V,E)\textit{G(V,E)} be a directed graph, where V={1,2,3,4,5}\textit{V} = \{ 1, 2, 3, 4, 5 \} is the set of vertices and E\textit{E} is the set of directed edges, as defined by the following adjacency matrix A.\textit{A}. A[i][j]={1,1≤j≤i≤50,otherwiseA [i][j] = \left\{\begin{matrix} 1, & 1 \leq j \leq i \leq 5 \\ 0, & \text{otherwise}\end{matrix}\right. A[i][j]=1A[i][j] = 1 …
Official PYQ2021AlgorithmsAsymptotic Worst Case Time and Space ComplexityMCQ · 1 mark
Consider the following three functions. f1=10nf2=nlog⁡nf3=nnf_1=10^n\quad f_2=n^{\log n}\quad f_3=n^{\sqrt {n}} Which one of the following options arranges the functions in the increasing order of asymptotic growth rate?
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 PYQ2021AlgorithmsMinimum Spanning TreesNAT · 1 mark
Consider the following undirected graph with edge weights as shown: The number of minimum-weight spanning trees of the graph is ___________.
Official PYQ2021AlgorithmsAsymptotic Worst Case Time and Space ComplexityMCQ · 2 marks
Consider the following recurrence relation. T(n)={T(n∕2)+T(2n∕5)+7nif  n>01if  n=0T\left ( n \right )=\left\{\begin{array} {lcl} T(n ∕ 2)+T(2n∕5)+7n & \text{if} \; n>0\\1 & \text{if}\; n=0 \end{array}\right. Which one of the following options is correct?
Official PYQ2021AlgorithmsAlgorithm Design: Greedy TechniquesMSQ · 2 marks
Define RnR_n to be the maximum amount earned by cutting a rod of length nn meters into one or more pieces of integer length and selling them. For i>0i>0, let p[i]p[i] denote the selling price of a rod whose length is ii meters. Consider the array of prices: …
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 PYQ2021AlgorithmsAsymptotic Worst Case Time and Space ComplexityNAT · 2 marks
Consider the following ANSI C\text{ANSI C} function: int SimpleFunction(int Y[], int n, int x) { int total = Y[0], loopIndex; for (loopIndex=1; loopIndex<=n-1; loopIndex++) total=x*total +Y[loopIndex]; return total; } Let Z\textsf{Z} be an array of 1010 elements with Z[i]=1\textsf{Z}[i]=1, for all ii such that 0≤i≤90 \leq i \leq 9. The value returned …
Official PYQ2021AlgorithmsMinimum Spanning TreesMCQ · 1 mark
Let GG be a connected undirected weighted graph. Consider the following two statements. S1S_1: There exists a minimum weight edge in GG which is present in every minimum spanning tree of GG. S2S_2: If every edge in GG has distinct weight, then GG has a unique minimum spanning tree. Which one of the following options is correct?
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 PYQ2021AlgorithmsAsymptotic Worst Case Time and Space ComplexityNAT · 1 mark
Consider the following ANSI C\text{ANSI C} function: int SomeFunction (int x, int y) { if ((x==1) || (y==1)) return 1; if (x==y) return x; if (x > y) return SomeFunction(x-y, y); if (y > x) return SomeFunction (x, y-x); } The value returned by SomeFunction(15, 255)\textrm{SomeFunction(15, 255)} is __________
Official PYQ2021AlgorithmsAlgorithm Design: Greedy TechniquesMCQ · 2 marks
Consider the string abbccddeee\textrm{abbccddeee}. Each letter in the string must be assigned a binary code satisfying the following properties: For any two letters, the code assigned to one letter must not be a prefix of the code assigned to the other letter. For any two letters of the same frequency, the letter which occurs earlier in the dictionary order is …
Official PYQ2021AlgorithmsAsymptotic Worst Case Time and Space ComplexityMCQ · 2 marks
For constants a≥1a \geq 1 and b>1b>1, consider the following recurrence defined on the non-negative integers: T(n)=a⋅T(nb)+f(n)T(n) = a \cdot T \left(\dfrac{n}{b} \right) + f(n) Which one of the following options is correct about the recurrence T(n)T(n)?
Official PYQ2021AlgorithmsMinimum Spanning TreesMSQ · 2 marks
Consider the following directed graph: Which of the following is/are correct about the graph?
Official PYQ2021AlgorithmsAsymptotic Worst Case Time and Space ComplexityNAT · 2 marks
Consider the following ANSI C\text{ANSI C} program #include <stdio.h> int foo(int x, int y, int q) { if ((x<=0) && (y<=0)) return q; if (x<=0) return foo(x, y-q, q); if (y<=0) return foo(x-q, y, q); return foo(x, y-q, q) + foo(x-q, y, q); } int main( ) { int r = foo(15, 15, 10); printf(“%d”, r); return 0; } The output of the program …