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
Let be a graph with vertices and edges. What is the tightest upper bound on the running time of Depth First Search on , when is represented as an adjacency matrix?
The number of distinct minimum spanning trees for the weighted graph below is _____
Suppose are sorted sequences having lengths respectively. They are to be merged into a single sequence by merging together two sequences at a time. The number of comparisons that will be needed in the worst case by the optimal algorithm for doing this is ____.
Consider two strings = "qpqrr" and = "pqprqrp". Let be the length of the longest common subsequence (not necessarily contiguous) between and and let be the number of such longest common subsequences between and . Then ___.
Consider the tree arcs of a BFS traversal from a source node in an unweighted, connected, undirected graph. The tree formed by the tree arcs is a data structure for computing
Which one of the following correctly determines the solution of the recurrence relation with ?
Consider the function func shown below: int func(int num) { int count = 0; while (num) { count++; num>>= 1; } return (count); } The value returned by func() is ________
Suppose you want to move from to on the number line. In each step, you either move right by a unit distance or you take a shortcut. A shortcut is simply a pre-specified pair of integers . Given a shortcut , if you are at position on the number line, you may directly move to . Suppose …
You have an array of elements. Suppose you implement quicksort by always choosing the central element of the array as the pivot. Then the tightest upper bound for the worst case performance is
Suppose depth first search is executed on the graph below starting at some unknown vertex. Assume that a recursive call to visit a vertex is made only after first checking that the vertex has not been visited earlier. Then the maximum possible recursion depth (including the initial call) is _________.
Let be the square matrix of size . Consider the following pseudocode. What is the expected output? C=100; for i=1 to n do for j=1 to n do { Temp = A[i][j]+C; A[i][j] = A[j][i]; A[j][i] = Temp -C; } for i=1 to n do for j=1 to n do output (A[i][j]);
Consider the following function: int unknown(int n){ int i, j, k=0; for (i=n/2; i<=n; i++) for (j=2; j<=n; j=j*2) k = k + n/2; return (k); } The return value of the function is
The number of elements that can be sorted in time using heap sort is
What is the time complexity of Bellman-Ford single-source shortest path algorithm on a complete graph of n vertices?
Which one of the following is the tightest upper bound that represents the number of swaps required to sort numbers using selection sort?
A list of strings, each of length , is sorted into lexicographic order using the merge-sort algorithm. The worst case running time of this computation is
Let be a weighted graph with edge weights greater than one and be the graph constructed by squaring the weights of edges in . Let and be the minimum spanning trees of and , respectively, with total weights and . Which of the following statements is TRUE?
Let and denote respectively, the worst case and average case running time of an algorithm executed on an input of size . Which of the following is ALWAYS TRUE?
The recurrence relation capturing the optimal execution time of the problem with discs is
An undirected graph contains nodes named . Two nodes are connected if and only if . Each edge is assigned a weight . A sample graph with is shown below. The length of the path from to in the MST of previous question with …
