uiz Space

September 2025 term · Programming, Data Structures and Algorithms using Python · BSCS2002

Programming, Data Structures and Algorithms using Python End Term: 21 December 2025 (September 2025 term)

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.

Questions
50
Marks
200
Duration
180 min
MCQ
32
MSQ
4
Numerical
14

Updated

Official paper: Programming, Data Structures And Algorithms Using Python 18 Dec 25 · No negative marking.

Question 1

+4 marksOne correct option

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.

  1. A

    [5,31,71,41]

  2. B

    [15,7,3,6,8,34]

  3. C

    [11,3,15,31]

  4. D

    [5,4,13,30]

Show answer

Correct answer

  • D

    [5,4,13,30]

Question 2

+4 marksOne correct option

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.

  1. A

    [56,4,70,40]

  2. B

    [6,8,34,13,5,9]

  3. C

    [6,11,4,30]

  4. D

    [6,4,2,30]

Show answer

Correct answer

  • C

    [6,11,4,30]

Question 3

+4 marksOne correct option

Match the correct asymptotic complexity for each function.

  1. A

    1-b, 2-c, 3-a, 4-d, 5-e

  2. B

    1-a, 2-d, 3-b, 4-c, 5-e

  3. C

    1-e, 2-c, 3-b, 4-a, 5-d

  4. D

    1-a, 2-c, 3-b, 4-d, 5-e

Show answer

Correct answer

  • D

    1-a, 2-c, 3-b, 4-d, 5-e

Question 4

+4 marksOne correct option

Match the correct asymptotic complexity for each function.

  1. A

    1-b, 2-c, 3-d, 4-e, 5-a

  2. B

    1-a, 2-c, 3-d, 4-e, 5-b

  3. C

    1-b, 2-c, 3-e, 4-d, 5-a

  4. D

    1-a, 2-c, 3-e, 4-d, 5-b

Show answer

Correct answer

  • A

    1-b, 2-c, 3-d, 4-e, 5-a

Question 5

+4 marksOne correct option

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?

  1. A

    [10, 15, 20, 25, 17]

  2. B

    [10, 25, 20, 17, 15]

  3. C

    [10, 15, 25, 20, 17]

  4. D

    [25, 17, 20, 10, 15]

Show answer

Correct answer

  • A

    [10, 15, 20, 25, 17]

Question 6

+4 marksOne correct option

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?

  1. A

    [11, 15, 18, 13, 12]

  2. B

    [15, 12, 18, 13, 11]

  3. C

    [11, 12, 18, 13, 15]

  4. D

    [11, 12, 13, 15, 18]

Show answer

Correct answer

  • C

    [11, 12, 18, 13, 15]

Question 7

+4 marksOne or more correct options

Which of the following scenarios is an example where linear search is more practical or efficient than the binary search?

Select all that apply.

  1. A

    The list has only 3–4 elements.

  2. B

    The list is unsorted and searching must be done immediately.

  3. C

    The element being searched is at the middle index of a large sorted list.

  4. D

    The list changes frequently, making it expensive to maintain sorted order.

  5. E

    The list is sorted and stored in an array with random access available.

Show answer

Correct answers

  • A

    The list has only 3–4 elements.

  • B

    The list is unsorted and searching must be done immediately.

  • D

    The list changes frequently, making it expensive to maintain sorted order.

Question 8

+4 marksOne or more correct options

Which of the following scenarios is an example where linear search is more practical or efficient than binary search?

Select all that apply.

  1. A

    Searching for an element in linked list.

  2. B

    Searching for an element in an unsorted list.

  3. C

    Searching for an element in a very large sorted list.

  4. D

    Searching element is at the first index position of the list.

  5. E

    The searching element is at the last index position of the list

Show answer

Correct answers

  • A

    Searching for an element in linked list.

  • B

    Searching for an element in an unsorted list.

  • D

    Searching element is at the first index position of the list.

Question 9

+4 marksOne correct option

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?

  1. A

    Traverse the linked list once, comparing each node with its immediate successor and count duplicates.

  2. B

    Traverse the linked list once and store each node’s value in a hash table to count duplicates.

  3. C

    Use a nested loop to compare each node with all other nodes and count duplicates.

  4. D

    Recursively traverse the linked list from the tail and count duplicates.

Show answer

Correct answer

  • A

    Traverse the linked list once, comparing each node with its immediate successor and count duplicates.

Question 10

+4 marksOne correct option

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?

  1. A

    25

  2. B

    30

  3. C

    7

  4. D

    40

Show answer

Correct answer

  • B

    30

Question 11

+4 marksNumerical answer

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?

Show answer

Correct answer: 70

Question 12

+4 marksOne correct option

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?

  1. A

    Recursively remove duplicates from the tail of the linked list.

  2. B

    Iterate through the linked list and use a nested loop to find duplicate values.

  3. C

    Traverse the linked list once, comparing each node with its immediate successor.

  4. D

    Traverse the linked list once and store non-duplicate elements in a new linked list.

Show answer

Correct answer

  • C

    Traverse the linked list once, comparing each node with its immediate successor.

Question 13

+4 marksNumerical answer

A directed graph G has 7 vertices. What is the maximum number of edges in G?

Show answer

Correct answer: 42

Question 14

+4 marksNumerical answer

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?

Show answer

Correct answer: 150

Question 15

+4 marksNumerical answer

Consider the following DAG.

How many valid topological sorts exist?

Show answer

Correct answer: 6

Question 16

+4 marksOne correct option

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?

  1. A

    (4,7)

  2. B

    (5,7)

  3. C

    (0,3)

  4. D

    (0,7)

Show answer

Correct answer

  • D

    (0,7)

Question 17

+4 marksOne correct option

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?

  1. A

    0

  2. B

    2

  3. C

    4

  4. D

    3

Show answer

Correct answer

  • C

    4

Question 18

+4 marksNumerical answer

Consider the following DAG.

How many valid topological sorts exist?

Show answer

Correct answer: 2

Question 19

+4 marksOne correct option

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 ?

  1. A

    9

  2. B

    8

  3. C

    7

  4. D

    6

Show answer

Correct answer

  • D

    6

Question 20

+4 marksOne correct option
  1. A
  2. B
  3. C
  4. D
Show answer

Correct answer

  • A

Question 21

+4 marksOne or more correct options

In the Floyd–Warshall algorithm, which of the following are true?

Select all that apply.

  1. A

    It uses dynamic programming.

  2. B

    It can detect negative cycles.

  3. C

    It maintains a predecessor matrix for path reconstruction (when implemented with one).

  4. D

    It cannot be applied to undirected graphs.

Show answer

Correct answers

  • A

    It uses dynamic programming.

  • B

    It can detect negative cycles.

  • C

    It maintains a predecessor matrix for path reconstruction (when implemented with one).

Question 22

+4 marksOne correct option

Consider the following graph.

What is the shortest distance from node 0 to node 5?

  1. A

    7

  2. B

    8

  3. C

    9

  4. D

    11

Show answer

Correct answer

  • A

    7

Question 23

+4 marksNumerical answer

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 __.

Show answer

Correct answer: 16

Question 24

+4 marksOne correct option

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 ___?

  1. A

    Run faster

  2. B

    Run slower

  3. C

    Produce wrong results

  4. D

    Detect the cycle

Show answer

Correct answer

  • B

    Run slower

Question 25

+4 marksOne correct option

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 _____.

  1. A

    4

  2. B

    3

  3. C

    2

  4. D

    1

Show answer

Correct answer

  • C

    2

Question 26

+4 marksOne correct option
  1. A
  2. B
  3. C

    Some of the edges in G must have the same weight.

  4. D

    All edges in G must have the same weight.

Show answer

Correct answer

  • C

    Some of the edges in G must have the same weight.

Question 27

+4 marksOne or more correct options

Consider the following max-heap.

Which of the following cannot be the last element inserted into the heap?

Select all that apply.

  1. A

    77

  2. B

    10

  3. C

    31

  4. D

    17

  5. E

    36

Show answer

Correct answers

  • C

    31

  • D

    17

Question 28

+4 marksOne correct option

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 _______.

  1. A

    2

  2. B

    3

  3. C

    4

  4. D

    5

Show answer

Correct answer

  • A

    2

Question 29

+4 marksOne correct option

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__.

  1. A

    [18, 20, 28, 40, 25, 30, 50, 45, 35]

  2. B

    [18, 25, 20, 40, 35, 30, 28, 50, 45]

  3. C

    [18, 20, 28, 25, 35, 30, 40, 50, 45]

  4. D

    [18, 25, 20, 35, 40, 28, 30, 50, 45]

Show answer

Correct answer

  • C

    [18, 20, 28, 25, 35, 30, 40, 50, 45]

Question 30

+4 marksOne correct option

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__.

  1. A

    [78, 62, 51, 31, 34, 29, 30, 42, 45]

  2. B

    [78, 62, 31, 51, 34, 29, 30, 45, 42]

  3. C

    [78, 62, 31, 51, 34, 30, 29, 45, 42]

  4. D

    [78, 62, 31, 51, 34, 29, 30, 42, 45]

Show answer

Correct answer

  • D

    [78, 62, 31, 51, 34, 29, 30, 42, 45]

Question 31

+4 marksNumerical answer

What is the maximum number of nodes in an AVL tree of height 9? Consider that the height of the empty tree is 0.

Show answer

Correct answer: 511

Question 32

+4 marksNumerical answer

What is the minimum number of nodes in an AVL tree of height 7? Consider that the height of the empty tree is 0.

Show answer

Correct answer: 33

Question 33

+4 marksNumerical answer
Show answer

Correct answer: 45

Question 34

+4 marksNumerical answer
Show answer

Correct answer: 132

Question 35

+4 marksOne correct option

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. A

    {1, 4, 6}

  2. B

    {1, 3, 4}

  3. C

    {1, 5, 7}

  4. D

    {1, 2, 6}

Show answer

Correct answer

  • A

    {1, 4, 6}

Question 36

+4 marksOne correct option

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. A

    {1, 2, 5}

  2. B

    {1, 3, 4}

  3. C

    {1, 4, 5}

  4. D

    {1, 2, 3}

Show answer

Correct answer

  • B

    {1, 3, 4}

Question 37

+4 marksOne correct option

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___

  1. A

    5

  2. B

    4

  3. C

    3

  4. D

    2

Show answer

Correct answer

  • A

    5

Question 38

+4 marksOne correct option

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___.

  1. A

    5

  2. B

    4

  3. C

    3

  4. D

    2

Show answer

Correct answer

  • C

    3

Question 39

+4 marksOne correct option
  1. A
  2. B
  3. C
  4. D
Show answer

Correct answer

  • D

Question 40

+4 marksOne correct option
  1. A
  2. B
  3. C
  4. D
Show answer

Correct answer

  • D

Question 41

+4 marksNumerical 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]

Show answer

Correct answer: 17

Question 42

+4 marksNumerical answer

Consider the following function MoM.

Show answer

Correct answer: 16

Question 43

+4 marksOne correct option

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.

  1. A

    10

  2. B

    9

  3. C

    8

  4. D

    7

Show answer

Correct answer

  • B

    9

Question 44

+4 marksOne correct option

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.

  1. A

    10

  2. B

    9

  3. C

    8

  4. D

    7

Show answer

Correct answer

  • A

    10

Question 45

+4 marksNumerical answer

Consider the following grid.

Show answer

Correct answer: 22

Question 46

+4 marksNumerical answer

Consider the following grid.

Show answer

Correct answer: 18

Question 47

+4 marksOne correct option
  1. A
  2. B
  3. C
  4. D
Show answer

Correct answer

  • C

Question 48

+4 marksOne correct option
  1. A
  2. B
  3. C
  4. D
Show answer

Correct answer

  • D

Question 49

+4 marksOne correct option
  1. A

    16

  2. B

    15

  3. C

    14

  4. D

    13

Show answer

Correct answer

  • B

    15

Question 50

+4 marksOne correct option
  1. A

    9

  2. B

    10

  3. C

    11

  4. D

    12

Show answer

Correct answer

  • C

    11