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 PYQ2021AlgorithmsGraph Traversals (BFS, DFS)NAT · 2 marks
In a directed acyclic graph with a source vertex s\textsf{s}, the quality-score\textit{quality-score} of a directed path is defined to be the product of the weights of the edges on the path. Further, for a vertex vv other than s\textsf{s}, the quality-score of vv is defined to be the maximum among the quality-scores of all the paths from s\textsf{s} to …
Official PYQ2020AlgorithmsAsymptotic Worst Case Time and Space ComplexityMCQ · 1 mark
For parameters aa and bb, both of which are ω(1)\omega(1), T(n)=T(n1/a)+1T(n) = T(n^{1/a})+1, and T(b)=1T(b)=1. Then T(n)T(n) is
Official PYQ2020AlgorithmsSearching, Sorting, HashingNAT · 1 mark
Consider a double hashing scheme in which the primary hash function is h1(k)=k mod 23h_1(k)= k \text{ mod } 23, and the secondary hash function is h2(k)=1+(k mod 19)h_2(k)=1+(k \text{ mod } 19). Assume that the table size is 2323. Then the address returned by probe 11 in the probe sequence (assume that the probe sequence begins at probe 00) for key value k=90k=90 …
Official PYQ2020AlgorithmsMinimum Spanning TreesMCQ · 2 marks
Let G=(V,E)G = (V, E) be a weighted undirected graph and let TT be a Minimum Spanning Tree (MST) of GG maintained using adjacency lists. Suppose a new weighed edge (u,v)∈V×V(u, v) \in V \times V is added to GG. The worst case time complexity of determining if TT is still an MST of the resultant graph is
Official PYQ2020AlgorithmsShortest Paths (Dijkstra, Bellman-Ford)MCQ · 2 marks
Let G=(V,E)G = (V,E) be a directed, weighted graph with weight function w:E→Rw: E \rightarrow \mathbb{R}. For some function f:V→Rf: V \rightarrow \mathbb{R}, for each edge(u,v)∈E(u,v)\in E, define w′(u,v){w}'(u,v) as w(u,v)+f(u)−f(v)w(u,v)+f(u)-f(v). Which one of the options completes the following sentence so that it is TRUE? “The shortest paths in GG under ww are shortest …
Official PYQ2020AlgorithmsAsymptotic Worst Case Time and Space ComplexityNAT · 2 marks
Consider the following C functions. int tob (int b, int* arr) { int i; for (i = 0; b>0; i++) { if (b%2) arr [i] = 1; else arr[i] = 0; b = b/2; } return (i); } int pp(int a, int b) { int arr[20]; int i, tot = 1, ex, len; ex = a; len = tob(b, arr); for (i=0; i<len ; i++) { if (arr[i] ==1) tot = tot * ex; ex= ex*ex; } return (tot) ; } The value returned …
Official PYQ2020AlgorithmsMinimum Spanning TreesNAT · 2 marks
Consider a graph G=(V,E)G = (V,E), where V={v1,v2,…,v100}V = \{v_1,v_2, \dots ,v_{100}\}, E={(vi,vj)∣1≤i<j≤100}E = \{(v_i,v_j) \mid 1\leq i < j \leq 100\}, and weight of the edge (vi,vj)(v_i,v_j) is ∣i–j∣\mid i – j \mid. The weight of minimum spanning tree of GG is _________
Official PYQ2019AlgorithmsSearching, Sorting, HashingNAT · 1 mark
An array of 2525 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 22 decimal places) is ________
Official PYQ2019AlgorithmsAlgorithm Design: Greedy TechniquesNAT · 1 mark
Consider a sequence of 1414 elements: A=[−5,−10,6,3,−1,−2,13,4,−9,−1,4,12,−3,0]A=[-5, -10, 6, 3, -1, -2, 13, 4, -9, -1, 4, 12, -3, 0]. The sequence sum S(i,j)=Σk=ijA[k]S(i,j) = \Sigma_{k=i}^j A[k]. Determine the maximum of S(i,j)S(i,j), where 0≤i≤j<140 \leq i \leq j <14. (Divide and conquer approach may be used.) Answer: ___________
Official PYQ2019AlgorithmsAsymptotic Worst Case Time and Space ComplexityMCQ · 2 marks
Consider the following C function. void convert (int n ) { if (n<0) printf{“%d”, n); else { convert(n/2); printf(“%d”, n%2); } } Which one of the following will happen when the function convert is called with any positive integer nn as argument?
Official PYQ2019AlgorithmsAsymptotic Worst Case Time and Space ComplexityMCQ · 2 marks
There are nn unsorted arrays: A1,A2,…,AnA_1, A_2, \dots, A_n. Assume that nn is odd.Each of A1,A2,…,AnA_1, A_2, \dots, A_n contains nn distinct elements. There are no common elements between any two arrays. The worst-case time complexity of computing the median of the medians of A1,A2,…,AnA_1, A_2, \dots , A_n is
Official PYQ2018AlgorithmsAlgorithm Design: Greedy TechniquesNAT · 2 marks
Consider the weights and values of items listed below. Note that there is only one unit of each item. …
Official PYQ2018AlgorithmsMinimum Spanning TreesNAT · 2 marks
Consider the following undirected graph GG: Choose a value for xx that will maximize the number of minimum weight spanning trees (MWSTs) of GG. The number of MWSTs of GG for this value of xx is ____.
Official PYQ2018AlgorithmsAsymptotic Worst Case Time and Space ComplexityNAT · 2 marks
Consider the following program written in pseudo-code. Assume that xx and yy are integers. Count (x, y) { if (y !=1 ) { if (x !=1) { print("*"); Count (x/2, y); } else { y=y-1; Count (1024, y); } } } The number of times that the printprint statement is executed by the call Count(1024,1024)Count(1024, 1024) is _____
Official PYQ2018AlgorithmsGraph Traversals (BFS, DFS)NAT · 2 marks
Let GG be a graph with 100!100! vertices, with each vertex labelled by a distinct permutation of the numbers 1,2,…,100.1, 2,\ldots, 100. There is an edge between vertices uu and vv if and only if the label of uu can be obtained by swapping two adjacent numbers in the label of vv. Let yy denote the degree of a vertex in GG, and zz denote the …
Official PYQ2018AlgorithmsGraph Traversals (BFS, DFS)MCQ · 2 marks
Let GG be a simple undirected graph. Let TDT_D be a depth first search tree of GG. Let TBT_B be a breadth first search tree of GG. Consider the following statements. No edge of GG is a cross edge with respect to TDT_D. (A cross edge in GG is between two nodes neither of which is an ancestor of the other in TDT_D). For every edge …
Official PYQ2018AlgorithmsAlgorithm Design: Dynamic ProgrammingMCQ · 2 marks
Assume that multiplying a matrix G1G_1 of dimension p×qp \times q with another matrix G2G_2 of dimension q×rq \times r requires pqrpqr scalar multiplications. Computing the product of nn matrices G1G2G3…GnG_1G_2G_3 \dots G_n can be done by parenthesizing in different ways. Define GiGi+1G_i G_{i+1} as an explicitly computed pair for a given …
Official PYQ2017AlgorithmsAlgorithm Design: Greedy TechniquesMCQ · 1 mark
Consider the following table: …
Official PYQ2017AlgorithmsAsymptotic Worst Case Time and Space ComplexityMCQ · 1 mark
Consider the following functions from positive integers to real numbers: 1010, n\sqrt{n}, nn, log⁡2n\log_{2}n, 100n\frac{100}{n}. The CORRECT arrangement of the above functions in increasing order of asymptotic complexity is:
Official PYQ2017AlgorithmsSearching, Sorting, HashingNAT · 1 mark
Let AA be an array of 3131 numbers consisting of a sequence of 00's followed by a sequence of 11's. The problem is to find the smallest index ii such that A[i]A\left [i \right ] is 11 by probing the minimum number of locations in AA. The worst case number of probes performed by an optimal algorithm is ____________.