Question 1
In the given graph, if we try to find the shortest path from node P to all other nodes using
Dijkstra’s algorithm, which node is the
node to be included in the visited set? Consider that P is the 1st visited node.
U
R
S
T

The IIT Madras BS Programming, Data Structures and Algorithms using Python (PDSA) Quiz 2 paper sat on 23 Nov 2025, in the September 2025 term: 16 questions for 50 marks in 120 minutes. Every question is below with its answer. Take it as a timed mock test to be marked, or read it through first.
In the given graph, if we try to find the shortest path from node P to all other nodes using
Dijkstra’s algorithm, which node is the
node to be included in the visited set? Consider that P is the 1st visited node.
U
R
S
T
Correct answer
S
Consider the following algorithm to solve the single source shortest path problem for a graph (directed or undirected) with positive integer edge weights and a source vertex s.Replace each edge (u,v) of weight w in the graph with a path of length w consisting of unit-weight edges from u to v (by introducing new intermediate vertices).
For example: edge (u, v) with weight w = 3
Run BFS on this modified graph from the source s to find the shortest path to each of the original vertices in the graph.
Which of the following statements is/are true?
I. The algorithm solves the single source shortest path problem correctly.
II. Although the size of the modified graph is larger than the original graph, the algorithm is as efficient as Dijkstra’s algorithm.
I is True but II is False
I is False but II is True
Both I and II are False
Both I and II are True
Correct answer
I is True but II is False
What is the weight of a minimum spanning tree in the graph given below?
Correct answer: 10
Let
be a connected undirected graph with distinct positive edge weights.Consider
a partition (cut) of the vertex set
into two non-empty subsets
and
such that:
•
, and
•
Let
be the minimum-weight edge among all edges that cross this cut, i.e., and
.
Which of the following statements is/are true?
I. For every pair of nodes
such that
and
, the edge
must lie on the shortest
path from
to
.
II. The edge
must be part of the minimum spanning tree (MST) of
.
I is True but II is False
I is False but II is True
Both I and II are False
Both I and II are True
Correct answer
I is False but II is True
Consider a max-heap of size
consisting of distinct elements and implemented using an array.
Which of the following operations can be performed in
time?
Inserting a new element
Deleting the maximum element
Merging with another max-heap of size
Update the value at the known index
Correct answers
Inserting a new element
Deleting the maximum element
Update the value at the known index
Consider a max-heap of size
consisting of distinct elements and implemented using an array.Which of the following statements is/are true about the max-heap?
The smallest element in the max-heap is always at a leaf node.
The smallest element in the max-heap is always located at one of the leaf nodes in the last level of the heap.
The second largest element in the max-heap must be located in the level immediately below the root (i.e., among the root’s children).
Finding the smallest element in the max-heap takes O(log n) time.
Correct answers
The smallest element in the max-heap is always at a leaf node.
The second largest element in the max-heap must be located in the level immediately below the root (i.e., among the root’s children).
The height of a binary search tree is defined as the number of nodes in the longest path from the
root to the leaf (both included). Consider a binary search tree
of height
. Note that need not be balanced.
Based on the above data, answer the given subquestions.
What is the worst-case running time complexity of the searching operation in
?
Correct answer
The height of a binary search tree is defined as the number of nodes in the longest path from the
root to the leaf (both included). Consider a binary search tree
of height
. Note that need not be balanced.
Based on the above data, answer the given subquestions.
Suppose the number of elements in
is
. Which of the following statement(s) is/are correct?
Correct answers
What is the minimum number of nodes possible in an AVL tree of height 6 ? Consider the tree with a single node having height 1.
Correct answer: 20
After inserting the following elements into an empty AVL Tree:
30, 20, 10, 28, 25, 40
Which of the following nodes will be the root in the final AVL Tree?
25
20
30
28
Correct answer
28
Given below is a set of characters and their frequencies:
Using Huffman encoding, construct the Huffman tree for this set of characters. What is the maximum number of bits needed to encode any character?
Correct answer: 3
Consider a problem scenario where you have to conduct
job interviews
. Each candidate is available only between start_time and end_time. If any interview finishes at time T, then the other interviews can be started at time T or afterwards.
Which of the following greedy strategies would you apply to schedule the interviews such that the maximum number of candidates can be interviewed without any conflicts?
Always choose the candidate whose start_time is at the earliest.
Always choose the candidate who is available for the shortest time.
Always choose the candidate whose availability overlaps with the minimum number of other candidates.
Always choose the candidate whose end_time is the earliest.
Correct answer
Always choose the candidate whose end_time is the earliest.
In an integer list L of length n, two elements L[i] and L[j] form an inversion if L[i] > L[j] and i < j.
Consider a list L of length n in which all elements are distinct and the list L has
inversions. The minimum possible value of n is ___.
Correct answer: 9
Which of the following statements is incorrect?
The worst case running time of Quick select algorithm to find the k^(th) largest number is O(n).
The time taken to find the median in an unsorted list using the Median of Medians (MoM) algorithm is O(n).
Quick select algorithm is an example of the divide-and-conquer approach to solving problems.
Using Fast Select (Quick Select using MoM for pivot selection) strategy, the worst-case running time will be O(n).
Correct answer
The worst case running time of Quick select algorithm to find the k^(th) largest number is O(n).
Consider the following recursive function to return the minimum element in the list L of size n. def find_min(L, low, high):
if low == high:
return L[low]
mid = (low + high) // 2
min1 = find_min(L, low, mid)
min2 = find_min(L, mid+1, high)
return min(min1, min2)
Which of the following represents the correct recurrence relation for the given function find_min?
,
,
,
,
Correct answer
,
Consider the following recurrences and choose the correct option.
1.
2.
Base Case:
and
and
and
and
Correct answer
and