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 directed graph with vertices. A path from to in is a sequence of vertices () such that for all in through . A simple path is a path in which no vertex appears more than once. Let be an array initialized as follows: …
The following are the starting and ending times of activities and respectively in chronological order: . Here, denotes the starting time and denotes the ending time of activity X. We need to schedule …
What is the weight of a minimum spanning tree of the following graph?
Let be an undirected graph with a subgraph . Weights are assigned to edges of as follows. A single-source shortest path algorithm is executed on the weighted graph with an arbitrary vertex of as the source. …
In a permutation , of n distinct integers, an inversion is a pair such that and . If all permutations are equally likely, what is the expected number of inversions in a randomly chosen permutation of ?
Consider the following recurrence relation for all The value of for is
The usual implementation of Insertion Sort to sort an array uses linear search to identify the position where an element is to be inserted into the already sorted part of the array. If, instead, we use binary search to identify the position, the worst case running time will
Consider the following graph: Among the following sequences: abeghf abfehg abfhge afghbe Which are the depth-first traversals of the above graph?
Consider the following three claims: where and are constants Which of the following claims are correct?
Ram and Shyam have been asked to show that a certain problem is Ram shows a polynomial time reduction from the problem to , and Shyam shows a polynomial time reduction from to Which of the following can be inferred from these reductions?
Consider the following function. For large values of , the return value of the function best approximates float f,(float x, int y) { float p, s; int i; for (s=1,p=1,i=1; i<y; i++) { p *= x/i; s += p; } return s; }
The cube root of a natural number is defined as the largest natural number such that . The complexity of computing the cube root of ( is represented by binary notation) is
The running time of the following algorithm Procedure If return () else return ; is best described by
Consider the following algorithm for searching for a given number in an unsorted array having distinct values: Choose an at random from If , then Stop else Goto 1; Assuming that is present in , what is the expected number of comparisons made by the algorithm before it terminates?
The solution to the recurrence equation is
Consider an undirected, unweighted graph . Let a breadth-first traversal of be done starting from a node . Let and be the lengths of the shortest paths from to and respectively in . If is visited before during the breadth-first traversal, which of the following statements is correct?
Let and be two positive functions of . Which of the following statements is correct?
Randomized quicksort is an extension of quicksort where the pivot is chosen randomly. What is the worst case complexity of sorting n numbers using Randomized quicksort?
Let be an undirected graph. Consider a depth-first traversal of , and let be the resulting depth-first search tree. Let be a vertex in and let be the first new (unvisited) vertex visited after visiting in the traversal. Which of the following statement is always true?
Let be an undirected connected graph with distinct edge weights. Let be the edge with maximum weight and the edge with minimum weight. Which of the following statements is false?
