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
An array of numbers is given, where is an even number. The maximum as well as the minimum of these numbers needs to be determined. Which of the following is TRUE about the number of comparisons needed?
Let be the minimum weight among all edge weights in an undirected connected graph. Let be a specific edge of weight . Which of the following is FALSE?
What is the of the following recursive function? int DoSomething (int n) { if (n <= 2) return 1; else return (DoSomething (floor (sqrt(n))) + n); }
In the following C function, let . 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?
In an unweighted, undirected connected graph, the shortest path from a node to every other node is computed most efficiently, in terms of time complexity, by
Which of the following sorting algorithms has the lowest worse-case complexity?
Given two arrays of numbers and where each number is or , the fastest algorithm to find the largest span such that or report that there is not such span,
Consider the following C-function in which and are two sorted integer arrays and 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 …
The median of elements can be found in time. Which one of the following is correct about the complexity of quick sort, in which median is selected as pivot?
Consider the following recurrence: Which one of the following is true?
A set can be represented by an array as follows: Consider the following algorithm in which , , and are Boolean arrays of size : algorithm zzz(x[], y[], z[]) { int i; for(i=0; i<n; ++i) z[i] = (x[i] ∧ ~y[i]) ∨ (~x[i] …
Let be a depth first search tree in an undirected graph . Vertices and are leaves of this tree . The degrees of both and in are at least . which one of the following statements is true?
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?
An element in an array is called a leader if it is greater than all elements to the right of it in . The best algorithm to find all leaders in an array
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?
Consider the following C-program fragment in which , and are integer variables. for( i = n, j = 0; i > 0; i /= 2, j +=i ); Let denote the value stored in the variable after termination of the for loop. Which one of the following is true?
Which one of the following in place sorting algorithms needs the minimum number of swaps?
To implement Dijkstra’s shortest path algorithm on unweighted graphs so that it runs in linear time, the data structure to be used is:
Consider a weighted complete graph on the vertex set such that the weight of the edge is . The weight of a minimum spanning tree of is:
We are given tasks . The execution of each task requires one unit of time. We can execute one task at a time. Each task has a profit and a deadline . Profit is earned if the task is completed before the end of the unit of time. …
