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 PYQ2007AlgorithmsAsymptotic Worst Case Time and Space ComplexityMCQ · 1 mark
An array of nn numbers is given, where nn is an even number. The maximum as well as the minimum of these nn numbers needs to be determined. Which of the following is TRUE about the number of comparisons needed?
Official PYQ2007AlgorithmsMinimum Spanning TreesMCQ · 1 mark
Let ww be the minimum weight among all edge weights in an undirected connected graph. Let ee be a specific edge of weight ww. Which of the following is FALSE?
Official PYQ2007AlgorithmsAsymptotic Worst Case Time and Space ComplexityMCQ · 1 mark
What is the time complexity\text{time complexity} of the following recursive function? int DoSomething (int n) { if (n <= 2) return 1; else return (DoSomething (floor (sqrt(n))) + n); }
Official PYQ2007AlgorithmsAsymptotic Worst Case Time and Space ComplexityMCQ · 1 mark
In the following C function, let n≥mn \geq m. int gcd(n,m) { if (n%m == 0) return m; n = n%m; return gcd(m,n); } How many recursive calls are made by this function?
Official PYQ2007AlgorithmsShortest Paths (Dijkstra, Bellman-Ford)MCQ · 1 mark
In an unweighted, undirected connected graph, the shortest path from a node SS to every other node is computed most efficiently, in terms of time complexity, by
Official PYQ2007AlgorithmsSearching, Sorting, HashingMCQ · 1 mark
Which of the following sorting algorithms has the lowest worse-case complexity?
Official PYQ2006AlgorithmsAsymptotic Worst Case Time and Space ComplexityMCQ · 1 mark
Given two arrays of numbers a1,...,ana_{1},...,a_{n} and b1,...,bnb_{1},...,b_{n} where each number is 00 or 11, the fastest algorithm to find the largest span (i,j)(i, j) such that ai+ai+1+⋯+aj=bi+bi+1+⋯+bja_{i}+a_{i+1}+\dots+a_{j}=b_{i}+b_{i+1}+\dots+b_{j} or report that there is not such span,
Official PYQ2006AlgorithmsAsymptotic Worst Case Time and Space ComplexityMCQ · 1 mark
Consider the following C-function in which a[n]a[n] and b[m]b[m] are two sorted integer arrays and c[n+m]c[n+m] be another integer array, void xyz(int a[], int b [], int c []){ int i,j,k; i=j=k=0; while ((i<n) && (j<m)) if (a[i] < b[j]) c[k++] = a[i++]; else c[k++] = b[j++]; } Which of the following condition(s) hold(s) after the termination …
Official PYQ2006AlgorithmsSearching, Sorting, HashingMCQ · 1 mark
The median of nn elements can be found in O(n)O(n) time. Which one of the following is correct about the complexity of quick sort, in which median is selected as pivot?
Official PYQ2006AlgorithmsAsymptotic Worst Case Time and Space ComplexityMCQ · 1 mark
Consider the following recurrence: T(n)=2T(n)+1,T(n)=2T\left ( \sqrt{n}\right )+1, T(1)=1T(1)=1 Which one of the following is true?
Official PYQ2006AlgorithmsAsymptotic Worst Case Time and Space ComplexityMCQ · 1 mark
A set XX can be represented by an array x[n]x[n] as follows: x[i]={1if i∈X0otherwisex\left [ i \right ]=\begin {cases} 1 & \text{if } i \in X \\ 0 & \text{otherwise} \end{cases} Consider the following algorithm in which xx, yy, and zz are Boolean arrays of size nn: algorithm zzz(x[], y[], z[]) { int i; for(i=0; i<n; ++i) z[i] = (x[i] ∧ ~y[i]) ∨ (~x[i] …
Official PYQ2006AlgorithmsGraph Traversals (BFS, DFS)MCQ · 1 mark
Let TT be a depth first search tree in an undirected graph GG. Vertices uu and νν are leaves of this tree TT. The degrees of both uu and νν in GG are at least 22. which one of the following statements is true?
Official PYQ2006AlgorithmsMinimum Spanning TreesMCQ · 1 mark
Consider the following graph: Which one of the following cannot be the sequence of edges added, in that order, to a minimum spanning tree using Kruskal’s algorithm?
Official PYQ2006AlgorithmsAlgorithm Design: Greedy TechniquesMCQ · 1 mark
An element in an array XX is called a leader if it is greater than all elements to the right of it in XX. The best algorithm to find all leaders in an array
Official PYQ2006AlgorithmsAsymptotic Worst Case Time and Space ComplexityMCQ · 1 mark
Let S be an NP-complete problem and Q and R be two other problems not known to be in NP. Q is polynomial time reducible to S and S is polynomial-time reducible to R. Which one of the following statements is true?
Official PYQ2006AlgorithmsAsymptotic Worst Case Time and Space ComplexityMCQ · 1 mark
Consider the following C-program fragment in which ii, jj and nn are integer variables. for( i = n, j = 0; i > 0; i /= 2, j +=i ); Let val(j)val(j) denote the value stored in the variable jj after termination of the for loop. Which one of the following is true?
Official PYQ2006AlgorithmsSearching, Sorting, HashingMCQ · 1 mark
Which one of the following in place sorting algorithms needs the minimum number of swaps?
Official PYQ2006AlgorithmsShortest Paths (Dijkstra, Bellman-Ford)MCQ · 1 mark
To implement Dijkstra’s shortest path algorithm on unweighted graphs so that it runs in linear time, the data structure to be used is:
Official PYQ2006AlgorithmsMinimum Spanning TreesMCQ · 1 mark
Consider a weighted complete graph GG on the vertex set {v1,v2,.....vn}\{v_1,v_2,.....v_n\} such that the weight of the edge (vi,vj)(v_i, v_j) is 2∣i−j∣2|i-j|. The weight of a minimum spanning tree of GG is:
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. …