Algorithms GATE CS PYQ Quiz

Subject Wise PYQs Quiz on Algorithms GATE CS from 2025 to 2000

Last Updated :
Discuss
Comments

Question 1

Assuming P β‰  NP, which of the following is TRUE?

  • NP-complete = NP

  • NP-complete ∩ P = 

  • NP-hard = NP

  • P = NP-complete

Question 2

Consider the following operation along with Enqueue and Dequeue operations on queues, where k is a global parameter

MultiDequeue(Q){ 
m = k
while (Q is not empty) and (m > 0) {
Dequeue(Q)
m = m – 1
}
}


What is the worst case time complexity of a sequence of n queue operations on an initially empty queue?

  • [Tex]\Theta{(n)}[/Tex]

  • [Tex]\Theta{(n+k)}[/Tex]

  • [Tex]\Theta{(nk)}[/Tex]

  • [Tex]\Theta{(n^{2})}[/Tex]

Question 3

Consider the following algorithm someAlgo that takes an undirected graph 𝐺 as input.

someAlgo(𝐺)

1. Let 𝑣 be any vertex in 𝐺. Run BFS on 𝐺 starting at 𝑣. Let 𝑒 be a vertex in 𝐺 at maximum distance from 𝑣 as given by the BFS.

2. Run BFS on 𝐺 again with 𝑒 as the starting vertex. Let 𝑧 be the vertex at maximum distance from 𝑒 as given by the BFS.

3. Output the distance between 𝑒 and 𝑧 in 𝐺. The output of someAlgo(𝑇) for the tree shown in the given figure is ___________. (Answer in integer)

someAlgo_BFS


  • 6

Question 4

An array 𝐴 of length 𝑛 with distinct elements is said to be bitonic if there is an index 1 ≀ 𝑖 ≀ 𝑛 such that 𝐴[1. . 𝑖] is sorted in the non-decreasing order and 𝐴[𝑖 + 1 . . 𝑛] 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 by an algorithm that searches for an element in a bitonic array 𝐴?

  • Θ(𝑛)

  • Θ(1)

  • Θ(log2 𝑛)

  • Θ(log 𝑛)

Question 5

A meld operation on two instances of a data structure combines them into one single instance of the same data structure. Consider the following data structures:

P: Unsorted doubly linked list with pointers to the head node and tail node of the list.

Q: Min-heap implemented using an array.

R: Binary Search Tree.

Which ONE of the following options gives the worst-case time complexities for meld operation on instances of size 𝑛 of these data structures?

  • P: Θ(1), Q: Θ(𝑛), R: Θ(𝑛)

  • P: Θ(1), Q: Θ(𝑛 log 𝑛), R: Θ(𝑛)

  • P: Θ(𝑛), Q: Θ(𝑛 log 𝑛), R: Θ(𝑛 2 )

  • P: Θ(1), Q: Θ(𝑛), R: Θ(𝑛 log 𝑛)

Question 6

Which of the following statements regarding Breadth First Search (BFS) and Depth First Search (DFS) on an undirected simple graph G is/are TRUE?

  • A DFS tree of 𝐺 is a Shortest Path tree of G

  • Every non-tree edge of G with respect to a DFS tree is a forward/back edge.

  • If (𝑒, 𝑣) is a non-tree edge of G with respect to a BFS tree, then the distances from the source vertex 𝑠 to 𝑒 and 𝑣 in the BFS tree are within Β±1 of each other.

  • Both BFS and DFS can be used to find the connected components of G

Question 7

The maximum value of π‘₯ such that the edge between the nodes B and C is included in every minimum spanning tree of the given graph is _________ . (answer in integer)

1
  • 5

Question 8

Consider an unordered list of 𝑁 distinct integers. What is the minimum number of element comparisons required to find an integer in the list that is NOT the largest in the list?

  • 1

  • N-1

  • N

  • 2N-1

Question 9

The pseudocode of a function fun() 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 𝐴[0, … ,29] be an array storing 30 distinct integers in descending order. The number of swap operations that will be performed, if the function fun() is called with 𝐴[0, … ,29] as argument, is __________. (Answer in integer) 

  • 435

Question 10

Consider the following recurrence relation: 

𝑇(𝑛) = 2𝑇(𝑛 βˆ’ 1) + 𝑛2𝑛 for 𝑛 > 0, 𝑇(0) = 1. 

Which ONE of the following options is CORRECT? 

  • 𝑇(𝑛) = Θ(𝑛22𝑛)

  • 𝑇(𝑛) = Θ(𝑛2𝑛)

  • 𝑇(𝑛) = Θ((log 𝑛)22𝑛

  • 𝑇(𝑛) = Θ(4𝑛)

There are 198 questions to complete.

Take a part in the ongoing discussion