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 PYQ2026AlgorithmsAsymptotic Worst Case Time and Space ComplexityMCQ · 1 mark
Consider the following recurrence relations: For all n>1n>1, T1(n)=4T1(n2)+T2(n)T2(n)=5T2(n4)+Θ(log⁡2n)\begin{array}{c} T_{1}(n)=4 T_{1}\left(\frac{n}{2}\right)+T_{2}(n) \\ T_{2}(n)=5 T_{2}\left(\frac{n}{4}\right)+\Theta\left(\log _{2} n\right) \end{array} Assume that for all n≤1,T1(n)=1n \leq 1, T_{1}(n)=1 and T2(n)=1T_{2}(n)=1. Which one of the following options is correct?
Official PYQ2026AlgorithmsSearching, Sorting, HashingMSQ · 1 mark
Let nn be an odd number greater than 100100. Consider a binary minheap with nn elements stored in an array PP whose index starts from 11. Which of the following indices of PP do/does NOT correspond to any leaf node of the minheap?
Official PYQ2026AlgorithmsSearching, Sorting, HashingMCQ · 1 mark
Consider a hash table P[0,1,…,10]P[0,1, \ldots, 10] that is initially empty. The hash table is maintained using open addressing with linear probing. The hash function used is h(x)=(x+7) mod 11h(x)=(x+7) \bmod 11. Consider the following sequence of insertions performed on PP :  1,13, 22, 15, 11, 24\text{ 1,13, 22, 15, 11, } 24 Which of the following positions in the hash table is/are empty …
Official PYQ2026AlgorithmsSearching, Sorting, HashingNAT · 1 mark
The height of a binary tree is the number of edges in the longest path from the root to a leaf in the tree. The maximum possible height of a full binary tree with 2323 nodes is ____\_\_\_\_.(answer in integer)
Official PYQ2026AlgorithmsSearching, Sorting, HashingMCQ · 2 marks
Let PP be the set of all integers from 11 to 1515. Consider any order of insertion of the elements of PP into a binary search tree that creates a complete binary tree. Which one of the following elements can NEVER be the third element that is inserted?
Official PYQ2026AlgorithmsGraph Traversals (BFS, DFS)MCQ · 2 marks
Let G(V,E)G(V, E) be an undirected, edge-weighted graph with integer weights. The weight of a path is the sum of the weights of the edges in that path. The length of a path is the number of edges in that path. Let s∈Vs \in V be a vertex in GG. For every u∈Vu \in V and for every k≥0k \geq 0, let dk(u)d_{k}(u) denote the weight of a shortest path (in terms …
Official PYQ2026AlgorithmsMinimum Spanning TreesMSQ · 2 marks
Let G(V,E)G(V, E) be a simple, undirected, edge-weighted graph with unique edge weights. Which of the following statements about the minimum spanning trees (MST) of GG is/are true?
Official PYQ2026AlgorithmsGraph Traversals (BFS, DFS)MSQ · 2 marks
Consider the following pseudocode for depth-first search (DFS) algorithm which takes a directed graph G(V,E)G(V, E) as input, where d[v]d[v] and f[v]f[v] are the discovery time and finishing time, respectively, of the vertex v∈Vv \in V. …
Official PYQ2026AlgorithmsAsymptotic Worst Case Time and Space ComplexityNAT · 2 marks
Consider the recursive functions represented by the following code segment: int bar(int n) { if (n == 1) return 0; else return 1 + bar(n/2); } int foo(int n) { if (n == 1) return 1; else return 1 + foo(bar(n)); } The smallest positive integer n for which f∘∘(n)\mathrm{f} \circ \circ(\mathrm{n}) returns 55 is ____\_\_\_\_. (answer in integer) Note: Ignore …
Official PYQ2026AlgorithmsSearching, Sorting, HashingNAT · 2 marks
The following sequence corresponds to the preorder traversal of a binary search tree TT : 50,25,13,40,30,47,75,60,70,80,7750,25,13,40,30,47,75,60,70,80,77 The position of the element 6060 in the postorder traversal of TT is ____\_\_\_\_ . (answer in integer) Note: The position begins with 11.
Official PYQ2026AlgorithmsAsymptotic Worst Case Time and Space ComplexityMCQ · 1 mark
Consider the following functions, where nn is a positive integer. n1/3,log⁡(n),log⁡(n!),2log⁡(n)n^{1 / 3}, \log (n), \log (n!), 2^{\log (n)} Which one of the following options lists the functions in increasing order of asymptotic growth rate? Note: Assume the base of log to be 22.
Official PYQ2026AlgorithmsAsymptotic Worst Case Time and Space ComplexityMSQ · 1 mark
Which of the following can be recurrence relation(s) corresponding to an algorithm with time complexity Θ(n)\Theta(n)?
Official PYQ2026AlgorithmsSearching, Sorting, HashingNAT · 1 mark
The keys 5,28,19,15,26,33,12,17,105,28,19,15,26,33,12,17,10 are inserted into a hash table using the hash function h(k)=k mod 9h(k)=k \bmod 9. The collisions are resolved by chaining. After all the keys are inserted, the length of the longest chain is ____\_\_\_\_. (answer in integer)
Official PYQ2026AlgorithmsSearching, Sorting, HashingNAT · 1 mark
Consider an array A=[10,7,8,19,41,35,25,31]A=[10,7,8,19,41,35,25,31]. Suppose the merge sort algorithm is executed on array AA to sort it in increasing order. The merge sort algorithm will carry out a total of 77 merge operations. A merge operation on sorted left array LL and sorted right array RR is said to be void if the output of the merge operation is the …
Official PYQ2026AlgorithmsShortest Paths (Dijkstra, Bellman-Ford)MCQ · 2 marks
Let GG be a weighted directed acyclic graph with mm edges and nn vertices. Given GG and a source vertex ss in GG, which one of the following options gives the worst case time complexity of the fastest algorithm to find the lengths of shortest paths from ss to all vertices that are reachable from ss in G?{G}?
Official PYQ2026AlgorithmsAsymptotic Worst Case Time and Space ComplexityMCQ · 2 marks
Consider an array AA of integers of size nn. The indices of AA run from 11 to nn. An algorithm is to be designed to check whether AA satisfies the condition given below. ∀i,j∈{1,…,n−1}\forall i, j \in\{1, \ldots, n-1\} such that i>j,(A[i+1]−A[i])>(A[j+1]−A[j])i>j,(A[i+1]-A[i])>(A[j+1]-A[j]) Which one of the following gives the worst case time complexity of the fastest …
Official PYQ2026AlgorithmsAlgorithm Design: Dynamic ProgrammingMCQ · 2 marks
Consider a table TT, where the elements T[i][j],0≤i,j≤nT[i][j], 0 \leq i, j \leq n, represent the cost of the optimal solutions of different subproblems of a problem that is being solved using a dynamic programming algorithm. The recursive formulation to compute the table entries is as follows: …
Official PYQ2026AlgorithmsSearching, Sorting, HashingMSQ · 2 marks
Consider a binary search tree (BST) with nn leaf nodes (n>0)(n>0). Given any node VV, the key present in the node is denoted as Val⁡(V)\operatorname{Val}(V). All the keys present in the given BST are distinct. The keys belong to the set of real numbers. For a node VV, let Suc⁡(V)\operatorname{Suc}(V) denote the node that is its inorder successor. If a …
Official PYQ2025AlgorithmsMinimum Spanning TreesMCQ · 1 mark
Let GG be any undirected graph with positive edge weights, and TT be a minimum spanning tree of GG. For any two vertices, uu and vv, let d1(u,v)d_{1}(u, v) and d2(u,v)d_{2}(u, v) be the shortest distances between uu and vv in GG and TT, respectively. Which ONE of the options is CORRECT for all possible G,T,uG, T, u and vv ?
Official PYQ2025AlgorithmsAsymptotic Worst Case Time and Space ComplexityMCQ · 1 mark
Consider the following recurrence relation: T(n)=2T(n−1)+n2n for n>0,T(0)=1T(n)=2 T(n-1)+n 2^{n} \text{ for } n>0, \quad T(0)=1 Which ONE of the following options is CORRECT?