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 PYQ2005AlgorithmsGraph Traversals (BFS, DFS)MCQ · 1 mark
Let ss and tt be two vertices in a undirected graph G=(V,E)G=(V,E) having distinct positive edge weights. Let [X,Y][X,Y] be a partition of VV such that s∈Xs \in X and t∈Yt \in Y. Consider the edge ee having the minimum weight amongst all those edges that have one vertex in XX and one vertex in YY. Let the weight of an edge ee denote the …
Official PYQ2005AlgorithmsAlgorithm Design: Greedy TechniquesMCQ · 1 mark
We are given 99 tasks T1,T2,…,T9T_1, T_2, \dots, T_9. The execution of each task requires one unit of time. We can execute one task at a time. Each task TiT_i has a profit PiP_i and a deadline did_i. Profit PiP_i is earned if the task is completed before the end of the dithd_i^{th} unit of time. …
Official PYQ2005AlgorithmsGraph Traversals (BFS, DFS)MCQ · 1 mark
Let ss and tt be two vertices in a undirected graph G=(V,E)G=(V,E) having distinct positive edge weights. Let [X,Y][X,Y] be a partition of VV such that s∈Xs \in X and t∈Yt \in Y. Consider the edge ee having the minimum weight amongst all those edges that have one vertex in XX and one vertex in YY. The edge ee must definitely belong to:
Official PYQ2005AlgorithmsAsymptotic Worst Case Time and Space ComplexityMCQ · 1 mark
double foo(int n) { int i; double sum; if(n == 0) { return 1.0; } else { sum = 0.0; for(i = 0; i < n; i++) { sum += foo(i); } return sum; } } The space complexity of the above code is?
Official PYQ2005AlgorithmsShortest Paths (Dijkstra, Bellman-Ford)MCQ · 1 mark
Let G(V,E)G(V,E) be an undirected graph with positive edge weights. Dijkstra’s single source shortest path algorithm can be implemented using the binary heap data structure with time complexity:
Official PYQ2005AlgorithmsAsymptotic Worst Case Time and Space ComplexityMCQ · 1 mark
Suppose T(n)=2T(n2)+nT(n) =2T (\frac{n}{2}) + n, T(0)=T(1)=1T(0) = T(1) =1 Which one of the following is FALSE?
Official PYQ2005AlgorithmsAsymptotic Worst Case Time and Space ComplexityMCQ · 1 mark
Consider the following C-program: void foo (int n, int sum) { int k = 0, j = 0; if (n == 0) return; k = n % 10; j = n/10; sum = sum + k; foo (j, sum); printf ("%d,",k); } int main() { int a = 2048, sum = 0; foo(a, sum); printf("%d\n", sum); } What does the above program print?
Official PYQ2005AlgorithmsMinimum Spanning TreesMCQ · 1 mark
An undirected graph GG has nn nodes. its adjacency matrix is given by an n×nn \times n square matrix whose (i) diagonal elements are 0’s and (ii) non-diagonal elements are 1’s. Which one of the following is TRUE?
Official PYQ2005AlgorithmsSearching, Sorting, HashingMCQ · 1 mark
Suppose there are ⌈log⁡n⌉\lceil \log n \rceil sorted lists of ⌊n/log⁡n⌋\lfloor n /\log n \rfloor elements each. The time complexity of producing a sorted list of all these elements is: (Hint:Use a heap data structure)
Official PYQ2004AlgorithmsAsymptotic Worst Case Time and Space ComplexityMCQ · 1 mark
The recurrence equation T(1)=1T(1) = 1 T(n)=2T(n−1)+n,n≥2T(n) = 2T(n-1) + n, n \geq 2 evaluates to
Official PYQ2004AlgorithmsAsymptotic Worst Case Time and Space ComplexityMCQ · 1 mark
Let A[1,…,n]A[1,\ldots,n] be an array storing a bit (11 or 00) at each location, and f(m)f(m) is a function whose time complexity is Θ(m)\Theta(m). Consider the following program fragment written in a C like language: counter = 0; for (i=1; i<=n; i++) { if (a[i] == 1) counter++; else {f (counter); counter = 0;} } The complexity of this program fragment …
Official PYQ2004AlgorithmsAsymptotic Worst Case Time and Space ComplexityMCQ · 1 mark
The time complexity of the following C function is (assume n>0n > 0) int recursive (int n) { if(n == 1) return (1); else return (recursive (n-1) + recursive (n-1)); }
Official PYQ2004AlgorithmsShortest Paths (Dijkstra, Bellman-Ford)MCQ · 1 mark
Suppose we run Dijkstra’s single source shortest path algorithm on the following edge-weighted directed graph with vertex PP as the source. In what order do the nodes get included into the set of vertices for which the shortest path distances are finalized?
Official PYQ2004AlgorithmsAsymptotic Worst Case Time and Space ComplexityMCQ · 1 mark
Consider the following C program main() { int x, y, m, n; scanf("%d %d", &x, &y); /* Assume x>0 and y>0*/ m = x; n = y; while(m != n) { if (m > n) m = m-n; else n = n-m; } printf("%d", n); } The program computes
Official PYQ2004AlgorithmsAsymptotic Worst Case Time and Space ComplexityMCQ · 1 mark
What does the following algorithm approximate? (Assume m>1,ϵ>0m > 1, \epsilon >0). x = m; y = 1; While (x-y > ϵ) { x = (x+y)/2; y = m/x; } print(x);
Official PYQ2004AlgorithmsAsymptotic Worst Case Time and Space ComplexityMCQ · 1 mark
Two matrices M1M_1 and M2M_2 are to be stored in arrays AA and BB respectively. Each array can be stored either in row-major or column-major order in contiguous memory locations. The time complexity of an algorithm to compute M1×M2M_1 \times M_2 will be
Official PYQ2004AlgorithmsAsymptotic Worst Case Time and Space ComplexityMCQ · 1 mark
The problem 3-SAT\text{3-SAT} and 2-SAT\text{2-SAT} are
Official PYQ2004AlgorithmsSearching, Sorting, HashingMCQ · 1 mark
The tightest lower bound on the number of comparisons, in the worst case, for comparison-based sorting is of the order of
Official PYQ2003AlgorithmsSearching, Sorting, HashingMCQ · 1 mark
In a permutation a1…ana_1\ldots a_n, of nn distinct integers, an inversion is a pair (ai,aj)(a_i, a_j) such that i<ji < j and ai>aj.a_i > a_j. What would be the worst case time complexity of the Insertion Sort algorithm, if the inputs are restricted to permutations of 1...n1. . . n with at most nn inversions?
Official PYQ2003AlgorithmsAsymptotic Worst Case Time and Space ComplexityMCQ · 1 mark
In the following CC program fragment, jj, kk, nn and TwoLog_n are integer variables, and AA is an array of integers. The variable nn is initialized to an integer ⩾3\geqslant 3, and TwoLog_n is initialized to the value of 2∗⌈log⁡2(n)⌉2^*\lceil \log_2(n) \rceil for (k = 3; k <= n; k++) A[k] = 0; for (k = 2; k <= TwoLog_n; k++) for (j = k+1; j …