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
The pseudocode of a function is given below: fun(int A[0,....,n-1]) { for i=0 to n-2 for j=0 to n-i-2 if (A[j]>A[j+1]) then swap A[j] and A[j+1] } Let be an array storing distinct integers in descending order. The number of swap operations that will be performed, if the function is called …
Let be an undirected and unweighted graph with vertices. Let denote the number of edges in a shortest path between vertices and in . Let the maximum value of such that , be . Let be any breadth-first-search tree of . Which ONE of the given options is CORRECT …
The maximum value of such that the edge between the nodes and is included in every minimum spanning tree of the given graph is _________. (answer in integer)
In a double hashing scheme, and are the auxiliary hash functions. The size of the hash table is . The hash function for the -th probe in the open address table is . The following keys are inserted in the given order: . The slot …
Consider the following algorithm someAlgo that takes an undirected graph as input. someAlgo (G) Let be any vertex in . Run BFS on starting at . Let be a vertex in at maximum distance from as given by the BFS. Run BFS on again with as the starting vertex. Let be the vertex at maximum distance …
Consider an unorders list of distinct integers. What is the minimum number of element comaparisons required to find an integer in the list that is NOT the largest in the list?
Which of the following statements regarding Breadth First Search (BFS) and Depth First Search (DFS) on an undirected simple graph is/are TRUE?
Let be an edge-weighted undirected graph with positive edge weights. Suppose a positive constant is added to the weight of every edge. Which ONE of the following statements is TRUE about the minimum spanning trees (MSTs) and shortest paths (SPs) in before and after the edge weight update?
An array of length with distinct elements is said to be bitonic if there is an index such that is sorted in the non-decreasing order and is sorted in the non-increasing order. Which ONE of the following represents the best possible asymptotic bound for the worst-case number of comparisons …
Given an integer array of size , we want to check if the array is sorted (in either ascending or descending order). An algorithm solves this problem by making a single pass through the array and comparing each element of the array only with its adjacent elements. The worst-case time complexity of this algorithm is
An array is heapified. Which one of the following options represents the first three elements in the heapified array?
Consider the following recurrence relation: Which one of the following options is CORRECT?
Let be a directed graph and a depth first search spanning tree in that is rooted at a vertex . Suppose is also a breadth first search tree in , rooted at . Which of the following statements is/are TRUE for every such graph and tree ?
The number of edges present in the forest generated by the traversal of an undirected graph with vertices is . The number of connected components in is __________.
Let be the recurrence relation defined as follows: Which one of the following statements is TRUE?
Let be an array containing integer values. The distance of is defined as the minimum number of elements in that must be replaced with another integer so that the resulting array is sorted in non-decreasing order. The distance of the array is ___________.
Consider an array that contains positive integers. A subarray of is defined to be a sequence of array locations with consecutive indices. The code snippet given below has been written to compute the length of the longest subarray of that contains at most two distinct integers. The …
The number of distinct minimum-weight spanning trees of the following graph is
An algorithm has to store several keys generated by an adversary in a hash table. The adversary is malicious who tries to maximize the number of collisions. Let be the number of keys, be the number of slots in the hash table, and . Which one of the following is the best hashing strategy to counteract the adversary?
Let and be functions of natural numbers given by and Which of the following statements is/are
