Question 1
Here is a function to return the count of odd numbers in the list. There is a logical error in this function.
Select the input list for which bad_count_odd produces incorrect output.
[5,31,71,41]
[15,7,3,6,8,34]
[11,3,15,31]
[5,4,13,30]

The IIT Madras BS Programming, Data Structures and Algorithms using Python (PDSA) End Term paper sat on 21 Dec 2025, in the September 2025 term: 50 questions for 200 marks in 180 minutes. Every question is below with its answer. Take it as a timed mock test to be marked, or read it through first.
Here is a function to return the count of odd numbers in the list. There is a logical error in this function.
Select the input list for which bad_count_odd produces incorrect output.
[5,31,71,41]
[15,7,3,6,8,34]
[11,3,15,31]
[5,4,13,30]
Correct answer
[5,4,13,30]
Here is a function to return the count of even numbers in the list. There is a logical error in this function.
Select the input list for which bad_count_even produces incorrect output.
[56,4,70,40]
[6,8,34,13,5,9]
[6,11,4,30]
[6,4,2,30]
Correct answer
[6,11,4,30]
Match the correct asymptotic complexity for each function.
1-b, 2-c, 3-a, 4-d, 5-e
1-a, 2-d, 3-b, 4-c, 5-e
1-e, 2-c, 3-b, 4-a, 5-d
1-a, 2-c, 3-b, 4-d, 5-e
Correct answer
1-a, 2-c, 3-b, 4-d, 5-e
Match the correct asymptotic complexity for each function.
1-b, 2-c, 3-d, 4-e, 5-a
1-a, 2-c, 3-d, 4-e, 5-b
1-b, 2-c, 3-e, 4-d, 5-a
1-a, 2-c, 3-e, 4-d, 5-b
Correct answer
1-b, 2-c, 3-d, 4-e, 5-a
Consider the below function for selection sort algorithm.
Assume that the list L=[25, 17, 20, 10, 15] is passed to the function selectionsort() as parameter. What will be the list L after the second pass of selection sort?
[10, 15, 20, 25, 17]
[10, 25, 20, 17, 15]
[10, 15, 25, 20, 17]
[25, 17, 20, 10, 15]
Correct answer
[10, 15, 20, 25, 17]
Consider the below function for selection sort algorithm.
Assume that the list L=[15, 12, 18, 13, 11] is passed to the function selectionsort() as parameter.
What will be the list L after the second pass of selection sort?
[11, 15, 18, 13, 12]
[15, 12, 18, 13, 11]
[11, 12, 18, 13, 15]
[11, 12, 13, 15, 18]
Correct answer
[11, 12, 18, 13, 15]
Which of the following scenarios is an example where linear search is more practical or efficient than the binary search?
The list has only 3–4 elements.
The list is unsorted and searching must be done immediately.
The element being searched is at the middle index of a large sorted list.
The list changes frequently, making it expensive to maintain sorted order.
The list is sorted and stored in an array with random access available.
Correct answers
The list has only 3–4 elements.
The list is unsorted and searching must be done immediately.
The list changes frequently, making it expensive to maintain sorted order.
Which of the following scenarios is an example where linear search is more practical or efficient than binary search?
Searching for an element in linked list.
Searching for an element in an unsorted list.
Searching for an element in a very large sorted list.
Searching element is at the first index position of the list.
The searching element is at the last index position of the list
Correct answers
Searching for an element in linked list.
Searching for an element in an unsorted list.
Searching element is at the first index position of the list.
Consider the following class Node:
Consider an implementation of a linked list where each node is created using the given class Node. Suppose head points to the first node of the linked list. Assume that the linked list is in sorted order.
What is an efficient way to count duplicate values in the linked list?
Traverse the linked list once, comparing each node with its immediate successor and count duplicates.
Traverse the linked list once and store each node’s value in a hash table to count duplicates.
Use a nested loop to compare each node with all other nodes and count duplicates.
Recursively traverse the linked list from the tail and count duplicates.
Correct answer
Traverse the linked list once, comparing each node with its immediate successor and count duplicates.
Suppose we are sorting a list of eight integers using quicksort, and we have just finished the first partitioning. The list looks like this: [12, 18, 25, 7, 30, 55, 60, 40]
Suppose the first element in the list is selected as the pivot for partitioning each time. Which of the following could have been the pivot for the first partitioning?
25
30
7
40
Correct answer
30
If you have an empty stack and you perform the following sequence of operations:
What is the value of the top element on the stack?
Correct answer: 70
Consider the following class Node:
Consider an implementation of a linked list where each node is created using the given class Node. Suppose head points to the first node of the linked list. Assume that the linked list is in sorted order.
What is an efficient way to remove all duplicate values in the linked list?
Recursively remove duplicates from the tail of the linked list.
Iterate through the linked list and use a nested loop to find duplicate values.
Traverse the linked list once, comparing each node with its immediate successor.
Traverse the linked list once and store non-duplicate elements in a new linked list.
Correct answer
Traverse the linked list once, comparing each node with its immediate successor.
A directed graph G has 7 vertices. What is the maximum number of edges in G?
Correct answer: 42
If you have an empty stack and you perform the following sequence of operations:
What is the value of the top element on the stack?
Correct answer: 150
Consider the following DAG.
How many valid topological sorts exist?
Correct answer: 6
There are 8 systems (0,..,7) connected in network as shown in the figure given below.
Which edge should we add to the network so that the network stays connected when one of the systems is down?
(4,7)
(5,7)
(0,3)
(0,7)
Correct answer
(0,7)
There are 7 systems (0,..,6) connected in a network as shown in the figure given below.
Which of the following system (node) failures will result in the network being disconnected?
0
2
4
3
Correct answer
4
Consider the following DAG.
How many valid topological sorts exist?
Correct answer: 2
Consider a directed graph given below:
Vertices: {0,1,2,3}
Edge weights: (0, 1) = 1 (0, 2) = 4 (1, 2) = 2 (1, 3) = 6 (2, 3) = 3
What is the shortest distance from node 0 to node 3 ?
9
8
7
6
Correct answer
6
Correct answer
In the Floyd–Warshall algorithm, which of the following are true?
It uses dynamic programming.
It can detect negative cycles.
It maintains a predecessor matrix for path reconstruction (when implemented with one).
It cannot be applied to undirected graphs.
Correct answers
It uses dynamic programming.
It can detect negative cycles.
It maintains a predecessor matrix for path reconstruction (when implemented with one).
Consider the following graph.
What is the shortest distance from node 0 to node 5?
7
8
9
11
Correct answer
7
Let G be a complete undirected graph on 4 vertices, having 6 edges with weights being 2, 5, 7, 9, 12, 14. The maximum possible total weight that a minimum weight spanning tree of G can have is __.
Correct answer: 16
Suppose we run the Bellman-Ford algorithm on a graph with non-negative edges. Then compared to Dijkstra's algorithm, the Bellman-Ford algorithm will ___?
Run faster
Run slower
Produce wrong results
Detect the cycle
Correct answer
Run slower
Consider a binary tree with 21 nodes, where the number of nodes with two children is 9. The number of nodes with one child node is _____.
4
3
2
1
Correct answer
2
Some of the edges in G must have the same weight.
All edges in G must have the same weight.
Correct answer
Some of the edges in G must have the same weight.
Consider the following max-heap.
Which of the following cannot be the last element inserted into the heap?
77
10
31
17
36
Correct answers
31
17
Consider a binary tree with 15 nodes, where the number of nodes with two children is 6. The number of nodes with one child node is _______.
2
3
4
5
Correct answer
2
If we perform the following operations in the given order on the min-heap [12, 25, 18, 40, 35, 30, 28, 50, 45] then the resulting min-heap would be__.
[18, 20, 28, 40, 25, 30, 50, 45, 35]
[18, 25, 20, 40, 35, 30, 28, 50, 45]
[18, 20, 28, 25, 35, 30, 40, 50, 45]
[18, 25, 20, 35, 40, 28, 30, 50, 45]
Correct answer
[18, 20, 28, 25, 35, 30, 40, 50, 45]
If we perform the following operations in the given order on the max-heap [89, 62, 31, 45, 51, 29, 30, 42, 34] then the resulting max-heap would be__.
[78, 62, 51, 31, 34, 29, 30, 42, 45]
[78, 62, 31, 51, 34, 29, 30, 45, 42]
[78, 62, 31, 51, 34, 30, 29, 45, 42]
[78, 62, 31, 51, 34, 29, 30, 42, 45]
Correct answer
[78, 62, 31, 51, 34, 29, 30, 42, 45]
What is the maximum number of nodes in an AVL tree of height 9? Consider that the height of the empty tree is 0.
Correct answer: 511
What is the minimum number of nodes in an AVL tree of height 7? Consider that the height of the empty tree is 0.
Correct answer: 33
Correct answer: 45
Correct answer: 132
For which of the following coin denominations does the Greedy strategy of choosing the largest coin that does not exceed the target fail to produce the minimum number of coins to make the amount 8?
{1, 4, 6}
{1, 3, 4}
{1, 5, 7}
{1, 2, 6}
Correct answer
{1, 4, 6}
For which of the following coin denominations does the Greedy strategy of choosing the largest coin that does not exceed the target fail to produce the minimum number of coins to make the amount 6?
{1, 2, 5}
{1, 3, 4}
{1, 4, 5}
{1, 2, 3}
Correct answer
{1, 3, 4}
In a list L, two elements L[i] and L[j] form an inversion if L[i] > L[j] and i < j . The total number of inversions for L = [3, 4, 2, 1, 5] is___
5
4
3
2
Correct answer
5
In a list L, two elements L[i] and L[j] form a significant inversion if L[i] > 2 * L[j] and i < j . The total number of significant inversions for L = [5, 4, 1, 2, 3] is___.
5
4
3
2
Correct answer
3
Correct answer
Correct answer
Consider the following function MoM.
What median value will be returned by the given MoM function for the following list? [1, 3, 7, 4, 3, 2, 7, 9, 15, 12, 19, 25, 16, 17, 11, 17, 21, 28, 18, 30]
Correct answer: 17
Consider the following function MoM.
Correct answer: 16
Consider the function mystery() that takes strings X and Y as input. What will mystery('ABCDFGH','ACDFHBG') return? LCS(X,Y) returns the length of the longest common subsequence of X and Y.
10
9
8
7
Correct answer
9
Consider the function mystery() that takes strings X and Y as input. What will mystery('XYITCRT','WTXITRY') return? LCS(X,Y) returns the length of the longest common subsequence of X and Y.
10
9
8
7
Correct answer
10
Consider the following grid.
Correct answer: 22
Consider the following grid.
Correct answer: 18
Correct answer
Correct answer
16
15
14
13
Correct answer
15
9
10
11
12
Correct answer
11