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 PYQ2003AlgorithmsGraph Traversals (BFS, DFS)MCQ · 1 mark
Let G=(V,E)G= (V,E) be a directed graph with nn vertices. A path from viv_i to vjv_j in GG is a sequence of vertices (vi,vi+1,…,vjv_{i},v_{i+1}, \dots , v_j) such that (vk,vk+1)∈E(v_k, v_{k+1}) \in E for all kk in ii through j−1j-1. A simple path is a path in which no vertex appears more than once. Let AA be an n×nn \times n array initialized as follows: …
Official PYQ2003AlgorithmsAlgorithm Design: Greedy TechniquesMCQ · 1 mark
The following are the starting and ending times of activities A,B,C,D,E,F,GA, B, C, D, E, F, G and HH respectively in chronological order: “as bs cs ae ds ce es fs be de gs ee fe hs ge he”“a_s \: b_s \: c_s \: a_e \: d_s \: c_e \: e_s \: f_s \: b_e \: d_e \: g_s \: e_e \: f_e \: h_s \: g_e \: h_e”. Here, xsx_s denotes the starting time and xex_e denotes the ending time of activity X. We need to schedule …
Official PYQ2003AlgorithmsMinimum Spanning TreesMCQ · 1 mark
What is the weight of a minimum spanning tree of the following graph?
Official PYQ2003AlgorithmsShortest Paths (Dijkstra, Bellman-Ford)MCQ · 1 mark
Let G=(V,E)G =(V,E) be an undirected graph with a subgraph G1=(V1,E1)G_1 = (V_1, E_1). Weights are assigned to edges of GG as follows. w(e)={0, if e∈E11, otherwisew(e) = \begin{cases} 0 \text{, if } e \in E_1 \\1 \text{, otherwise} \end{cases} A single-source shortest path algorithm is executed on the weighted graph (V,E,w)(V,E,w) with an arbitrary vertex v1v_1 of V1V_1 as the source. …
Official PYQ2003AlgorithmsSearching, Sorting, HashingMCQ · 1 mark
In a permutation a1...ana_1 ... a_n, of n distinct integers, an inversion is a pair (ai,aj)(a_i, a_j) such that i<ji < j and ai>aja_i > a_j. If all permutations are equally likely, what is the expected number of inversions in a randomly chosen permutation of 1...n1. . . n?
Official PYQ2003AlgorithmsAsymptotic Worst Case Time and Space ComplexityMCQ · 1 mark
Consider the following recurrence relation T(1)=1T(1)=1 T(n+1)=T(n)+⌊n+1⌋T(n+1) = T(n)+\lfloor \sqrt{n+1} \rfloor for all n≥1n \geq 1 The value of T(m2)T(m^2) for m≥1m \geq 1 is
Official PYQ2003AlgorithmsSearching, Sorting, HashingMCQ · 1 mark
The usual Θ(n2)\Theta(n^2) implementation of Insertion Sort to sort an array uses linear search to identify the position where an element is to be inserted into the already sorted part of the array. If, instead, we use binary search to identify the position, the worst case running time will
Official PYQ2003AlgorithmsGraph Traversals (BFS, DFS)MCQ · 1 mark
Consider the following graph: Among the following sequences: abeghf abfehg abfhge afghbe Which are the depth-first traversals of the above graph?
Official PYQ2003AlgorithmsAsymptotic Worst Case Time and Space ComplexityMCQ · 1 mark
Consider the following three claims: (n+k)m=Θ(nm)(n+k)^m = \Theta(n^m) where kk and mm are constants 2n+1=O(2n)2^{n+1} = O(2^n) 22n+1=O(2n)2^{2n+1} = O(2^n) Which of the following claims are correct?
Official PYQ2003AlgorithmsAsymptotic Worst Case Time and Space ComplexityMCQ · 1 mark
Ram and Shyam have been asked to show that a certain problem Π\Pi is NP-complete.\text{NP-complete}. Ram shows a polynomial time reduction from the 3-SAT\text{3-SAT} problem to Π\Pi, and Shyam shows a polynomial time reduction from Π\Pi to 3-SAT.\text{3-SAT.} Which of the following can be inferred from these reductions?
Official PYQ2003AlgorithmsAsymptotic Worst Case Time and Space ComplexityMCQ · 1 mark
Consider the following CC function. For large values of yy, the return value of the function ff best approximates float f,(float x, int y) { float p, s; int i; for (s=1,p=1,i=1; i<y; i++) { p *= x/i; s += p; } return s; }
Official PYQ2003AlgorithmsAsymptotic Worst Case Time and Space ComplexityMCQ · 1 mark
The cube root of a natural number nn is defined as the largest natural number mm such that (m3≤n)(m^3 \leq n) . The complexity of computing the cube root of nn (nn is represented by binary notation) is
Official PYQ2002AlgorithmsAsymptotic Worst Case Time and Space ComplexityMCQ · 1 mark
The running time of the following algorithm Procedure A(n)A(n) If n⩽2n \leqslant 2 return (11) else return (A(⌈n⌉))(A( \lceil \sqrt{n} \rceil)); is best described by
Official PYQ2002AlgorithmsSearching, Sorting, HashingMCQ · 1 mark
Consider the following algorithm for searching for a given number xx in an unsorted array A[1..n]A[1..n] having nn distinct values: Choose an ii at random from 1..n1..n If A[i]=xA[i] = x, then Stop else Goto 1; Assuming that xx is present in AA, what is the expected number of comparisons made by the algorithm before it terminates?
Official PYQ2002AlgorithmsAsymptotic Worst Case Time and Space ComplexityMCQ · 1 mark
The solution to the recurrence equation T(2k)=3T(2k−1)+1,T(1)=1T(2^k) = 3T(2^{k-1})+1, T(1) =1 is
Official PYQ2001AlgorithmsGraph Traversals (BFS, DFS)MCQ · 1 mark
Consider an undirected, unweighted graph GG. Let a breadth-first traversal of GG be done starting from a node rr. Let d(r,u)d(r,u) and d(r,v)d(r,v) be the lengths of the shortest paths from rr to uu and vv respectively in GG. If uu is visited before vv during the breadth-first traversal, which of the following statements is correct?
Official PYQ2001AlgorithmsAsymptotic Worst Case Time and Space ComplexityMCQ · 1 mark
Let f(n)=n2log⁡nf(n) = n^2 \log n and g(n)=n(log⁡n)10g(n) = n(\log n)^{10} be two positive functions of nn. Which of the following statements is correct?
Official PYQ2001AlgorithmsSearching, Sorting, HashingMCQ · 1 mark
Randomized quicksort is an extension of quicksort where the pivot is chosen randomly. What is the worst case complexity of sorting n numbers using Randomized quicksort?
Official PYQ2000AlgorithmsGraph Traversals (BFS, DFS)MCQ · 1 mark
Let GG be an undirected graph. Consider a depth-first traversal of GG, and let TT be the resulting depth-first search tree. Let uu be a vertex in GG and let vv be the first new (unvisited) vertex visited after visiting uu in the traversal. Which of the following statement is always true?
Official PYQ2000AlgorithmsMinimum Spanning TreesMCQ · 1 mark
Let GG be an undirected connected graph with distinct edge weights. Let emaxe_{max} be the edge with maximum weight and emine_{min} the edge with minimum weight. Which of the following statements is false?