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 functions and expressed in pseudocode as follows: Function_1 while n>1 do for i=1 to n do x = x + 1; end for n = ⌊n/2⌋; end while Function_2 for i = 1 to 100 * n do x = x + 1; end for Let and denote the number of times the statement is executed in …
Let . Let denote the powerset of . Consider an undirected graph whose vertex set is . For any is an edge in if and only if (i) , and (ii) either or . For any vertex in , the set of all possible orderings in which the …
Which one of the following statements is for all positive functions
Suppose we are given keys, hash table slots, and two simple uniform hash functions and Further suppose our hashing scheme uses for the odd keys and for the even keys. What is the expected number of keys in a slot?
Consider a simple undirected weighted graph all of whose edge weights are distinct. Which of the following statements about the minimum spanning trees of is/are
Let be a directed graph, where is the set of vertices and is the set of directed edges, as defined by the following adjacency matrix …
Consider the following three functions. Which one of the following options arranges the functions in the increasing order of asymptotic growth rate?
Consider the following array. Which algorithm out of the following options uses the least number of comparisons (among the array elements) to sort the above array in ascending order?
Consider the following undirected graph with edge weights as shown: The number of minimum-weight spanning trees of the graph is ___________.
Consider the following recurrence relation. Which one of the following options is correct?
Define to be the maximum amount earned by cutting a rod of length meters into one or more pieces of integer length and selling them. For , let denote the selling price of a rod whose length is meters. Consider the array of prices: …
Consider a hashing approach for -bit integer keys: There is a main hash table of size . The least significant bits of a key is used to index into the main hash table. Initially, the main hash table entries are empty. Thereafter, when more keys are hashed into it, to resolve collisions, the set of all keys corresponding to …
Consider the following function: int SimpleFunction(int Y[], int n, int x) { int total = Y[0], loopIndex; for (loopIndex=1; loopIndex<=n-1; loopIndex++) total=x*total +Y[loopIndex]; return total; } Let be an array of elements with , for all such that . The value returned …
Let be a connected undirected weighted graph. Consider the following two statements. : There exists a minimum weight edge in which is present in every minimum spanning tree of . : If every edge in has distinct weight, then has a unique minimum spanning tree. Which one of the following options is correct?
What is the worst-case number of arithmetic operations performed by recursive binary search on a sorted array of size ?
Consider the following function: int SomeFunction (int x, int y) { if ((x==1) || (y==1)) return 1; if (x==y) return x; if (x > y) return SomeFunction(x-y, y); if (y > x) return SomeFunction (x, y-x); } The value returned by is __________
Consider the string . Each letter in the string must be assigned a binary code satisfying the following properties: For any two letters, the code assigned to one letter must not be a prefix of the code assigned to the other letter. For any two letters of the same frequency, the letter which occurs earlier in the dictionary order is …
For constants and , consider the following recurrence defined on the non-negative integers: Which one of the following options is correct about the recurrence ?
Consider the following directed graph: Which of the following is/are correct about the graph?
Consider the following program #include <stdio.h> int foo(int x, int y, int q) { if ((x<=0) && (y<=0)) return q; if (x<=0) return foo(x, y-q, q); if (y<=0) return foo(x-q, y, q); return foo(x, y-q, q) + foo(x-q, y, q); } int main( ) { int r = foo(15, 15, 10); printf(“%d”, r); return 0; } The output of the program …
