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 PYQ2008AlgorithmsAsymptotic Worst Case Time and Space ComplexityMCQ · 1 mark
Consider the following C functions: int f1 (int n) { if(n == 0 || n == 1) return n; else return (2 * f1(n-1) + 3 * f1(n-2)); } int f2(int n) { int i; int X[N], Y[N], Z[N]; X[0] = Y[0] = Z[0] = 0; X[1] = 1; Y[1] = 2; Z[1] = 3; for(i = 2; i <= n; i++){ X[i] = Y[i-1] + Z[i-2]; Y[i] = 2 * X[i]; Z[i] = 3 * X[i]; } return X[n]; } f1(8)f1(8) and f2(8)f2(8) return …
Official PYQ2008AlgorithmsAsymptotic Worst Case Time and Space ComplexityMCQ · 1 mark
Let xnx_n denote the number of binary strings of length nn that contain no consecutive 00s. The value of x5x_5 is
Official PYQ2008AlgorithmsAlgorithm Design: Dynamic ProgrammingMCQ · 1 mark
The subset-sum problem is defined as follows. Given a set of nn positive integers, S={a1,a2,a3,…,an}S = \{ a_1, a_2, a_3, \dots , a_n \}, and positive integer WW, is there a subset of SS whose elements sum to WW? A dynamic program for solving this problem uses a 2-dimensional\text{2-dimensional} Boolean array, XX, with nn rows and W+1W+1 columns. …
Official PYQ2008AlgorithmsAlgorithm Design: Dynamic ProgrammingMCQ · 1 mark
The subset-sum problem is defined as follows. Given a set of nn positive integers, S={a1,a2,a3,…,an}S = \{ a_1, a_2, a_3, \dots , a_n \}, and positive integer WW, is there a subset of SS whose elements sum to WW? A dynamic program for solving this problem uses a 2-dimensional\text{2-dimensional} Boolean array, XX, with nn rows and W+1W+1 columns. …
Official PYQ2008AlgorithmsAsymptotic Worst Case Time and Space ComplexityMCQ · 1 mark
Let xnx_n denote the number of binary strings of length nn that contain no consecutive 00s. Which of the following recurrences does xnx_n satisfy?
Official PYQ2008AlgorithmsAsymptotic Worst Case Time and Space ComplexityMCQ · 1 mark
Consider the following C functions: int f1 (int n) { if(n == 0 || n == 1) return n; else return (2 * f1(n-1) + 3 * f1(n-2)); } int f2(int n) { int i; int X[N], Y[N], Z[N]; X[0] = Y[0] = Z[0] = 0; X[1] = 1; Y[1] = 2; Z[1] = 3; for(i = 2; i <= n; i++){ X[i] = Y[i-1] + Z[i-2]; Y[i] = 2 * X[i]; Z[i] = 3 * X[i]; } return X[n]; } The running time of f1(n)f1(n) …
Official PYQ2008AlgorithmsAsymptotic Worst Case Time and Space ComplexityMCQ · 1 mark
We have a binary heap on nn elements and wish to insert nn more elements (not necessarily one after another) into this heap. The total time required for this is
Official PYQ2008AlgorithmsShortest Paths (Dijkstra, Bellman-Ford)MCQ · 1 mark
Dijkstra's single source shortest path algorithm when run from vertex aa in the above graph, computes the correct shortest path distance to
Official PYQ2008AlgorithmsAsymptotic Worst Case Time and Space ComplexityMCQ · 1 mark
The subset-sum problem is defined as follows: Given a set SS of nn positive integers and a positive integer WW, determine whether there is a subset of SS whose elements sum to WW. An algorithm QQ solves this problem in O(nW)O(nW) time. Which of the following statements is false?
Official PYQ2008AlgorithmsSearching, Sorting, HashingMCQ · 1 mark
Consider the Quicksort algorithm. Suppose there is a procedure for finding a pivot element which splits the list into two sub-lists each of which contains at least one-fifth of the elements. Let T(n)T(n) be the number of comparisons required to sort nn elements. Then
Official PYQ2008AlgorithmsAsymptotic Worst Case Time and Space ComplexityMCQ · 1 mark
The minimum number of comparisons required to determine if an integer appears more than n2\frac{n}{2} times in a sorted array of nn integers is
Official PYQ2008AlgorithmsAsymptotic Worst Case Time and Space ComplexityMCQ · 1 mark
Consider the following functions: f(n)=2nf(n) = 2^n g(n)=n!g(n) = n! h(n)=nlog⁡nh(n) = n^{\log n} Which of the following statements about the asymptotic behavior of f(n)f(n), g(n)g(n) and h(n)h(n) is true?
Official PYQ2008AlgorithmsGraph Traversals (BFS, DFS)MCQ · 1 mark
The Breadth First Search algorithm has been implemented using the queue data structure. One possible order of visiting the nodes of the following graph is:
Official PYQ2008AlgorithmsAsymptotic Worst Case Time and Space ComplexityMCQ · 1 mark
The most efficient algorithm for finding the number of connected components in an undirected graph on nn vertices and mm edges has time complexity
Official PYQ2008AlgorithmsSearching, Sorting, HashingMCQ · 1 mark
Consider the following C program that attempts to locate an element xx in an array Y[ ]Y[ \ ] using binary search. The program is erroneous. f (int Y[10] , int x) { int i, j, k; i= 0; j = 9; do { k = (i+ j) / 2; if( Y[k] < x) i = k;else j = k; } while (Y[k] != x) && (i < j)) ; if(Y[k] == x) printf(" x is in the array ") ; else printf(" x is …
Official PYQ2007AlgorithmsAsymptotic Worst Case Time and Space ComplexityMCQ · 1 mark
Consider the following segment of C-code: int j, n; j = 1; while (j <= n) j = j * 2; The number of comparisons made in the execution of the loop for any n>0n > 0 is:
Official PYQ2007AlgorithmsAlgorithm Design: Greedy TechniquesMCQ · 1 mark
Suppose the letters a, b, c, d, e, fa, \,b, \,c, \,d, \,e, \,f have probabilities 12,14,18,116,132,132\dfrac{1}{2}, \dfrac{1}{4}, \dfrac{1}{8}, \dfrac{1}{16}, \dfrac{1}{32}, \dfrac{1}{32}, respectively. What is the average length of the Huffman code for the letters a, b, c, d, e, fa, \,b, \,c, \,d, \,e, \,f?
Official PYQ2007AlgorithmsGraph Traversals (BFS, DFS)MCQ · 1 mark
Consider the DAG with V={1,2,3,4,5,6}V = \{1,2,3,4,5,6\} shown below. Which of the following is not a topological ordering?
Official PYQ2007AlgorithmsAlgorithm Design: Greedy TechniquesMCQ · 1 mark
Suppose the letters a, b, c, d, e, fa, \,b, \,c, \,d, \,e, \,f have probabilities 12,14,18,116,132,132\frac{1}{2}, \frac{1}{4}, \frac{1}{8}, \frac{1}{16}, \frac{1}{32}, \frac{1}{32}, respectively. Which of the following is the Huffman code for the letter a, b, c, d, e, fa, \,b, \,c, \,d, \,e, \,f?
Official PYQ2007AlgorithmsAsymptotic Worst Case Time and Space ComplexityMCQ · 1 mark
Consider the following C program segment: int IsPrime (n) { int i, n; for (i=2; i<=sqrt(n);i++) if(n%i == 0) {printf("Not Prime \n"); return 0;} return 1; } Let T(n)T(n) denote number of times the forfor loop is executed by the program on input nn. Which of the following is TRUE?