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
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]; } and return …
Let denote the number of binary strings of length that contain no consecutive s. The value of is
The subset-sum problem is defined as follows. Given a set of positive integers, , and positive integer , is there a subset of whose elements sum to ? A dynamic program for solving this problem uses a Boolean array, , with rows and columns. …
The subset-sum problem is defined as follows. Given a set of positive integers, , and positive integer , is there a subset of whose elements sum to ? A dynamic program for solving this problem uses a Boolean array, , with rows and columns. …
Let denote the number of binary strings of length that contain no consecutive s. Which of the following recurrences does satisfy?
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 …
We have a binary heap on elements and wish to insert more elements (not necessarily one after another) into this heap. The total time required for this is
Dijkstra's single source shortest path algorithm when run from vertex in the above graph, computes the correct shortest path distance to
The subset-sum problem is defined as follows: Given a set of positive integers and a positive integer , determine whether there is a subset of whose elements sum to . An algorithm solves this problem in time. Which of the following statements is false?
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 be the number of comparisons required to sort elements. Then
The minimum number of comparisons required to determine if an integer appears more than times in a sorted array of integers is
Consider the following functions: Which of the following statements about the asymptotic behavior of , and is true?
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:
The most efficient algorithm for finding the number of connected components in an undirected graph on vertices and edges has time complexity
Consider the following C program that attempts to locate an element in an array 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 …
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 is:
Suppose the letters have probabilities , respectively. What is the average length of the Huffman code for the letters ?
Consider the DAG with shown below. Which of the following is not a topological ordering?
Suppose the letters have probabilities , respectively. Which of the following is the Huffman code for the letter ?
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 denote number of times the loop is executed by the program on input . Which of the following is TRUE?
