uiz Space

January 2026 term · Programming in Python · BSCS1002

Programming in Python Quiz 2: 12 April 2026 (January 2026 term)

The IIT Madras BS Programming in Python (Python) Quiz 2 paper sat on 12 Apr 2026, in the January 2026 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.

Questions
16
Marks
50
Duration
120 min
MCQ
10
MSQ
2
Written
4

Updated

Official paper: Programming, Data Structures And Algorithms Using Python 06 Apr 26 · No negative marking.

Question 1

+3 marksOne correct option

Which of the following statements is/are correct about Dijkstra's algorithm to find the shortest path? I. The shortest path returned by Dijkstra's algorithm always passes through the least number of vertices. II. To decide which vertex to visit next, Dijkstra's algorithm selects the vertex with the minimum known distance among all unvisited vertices.

  1. A

    Only I is correct

  2. B

    Only II is correct

  3. C

    Both I and II are correct

  4. D

    Both I and II are incorrect

Show answer

Correct answer

  • B

    Only II is correct

Question 2

+3 marksOne correct option

The Bellman–Ford algorithm can be used to detect the presence of a negative-weight cycle reachable from the source vertex in a weighted directed graph. Which of the following correctly explains how Bellman–Ford detects a negative-weight cycle?

  1. A

    A negative-weight cycle exists if the shortest distance to any vertex becomes negative at any point during the algorithm.

  2. B

    If, after performing exactly relaxation iterations, an additional relaxation of any edge further reduces a distance value, then a negative-weight cycle is present.

  3. C

    If the algorithm encounters an edge with a negative weight during relaxation, it immediately concludes that a negative-weight cycle exists.

  4. D

    If multiple shortest paths exist between two vertices, the graph must contain a negative-weight cycle.

Show answer

Correct answer

  • B

    If, after performing exactly relaxation iterations, an additional relaxation of any edge further reduces a distance value, then a negative-weight cycle is present.

Question 3

+3 marksOne correct option

Which of the following correctly represents the final max-heap after inserting elements 1, 2, 3, 5, 7, 6, and 4 in the given order one by one, starting with an empty heap? Note:- Ensure that the max-heap property is maintained after each insertion.

  1. A

    —

  2. B

    —

  3. C

    —

  4. D

    —

Show answer

Correct answer

  • D

    —

Question 4

+3 marksOne correct option

The maximum and minimum number of nodes possible in a binary search tree of height 8 are ___. Assume that the height of an empty tree is 0, and the height of a tree with a single node is 1.

  1. A

    255 and 8, respectively

  2. B

    256 and 7, respectively

  3. C

    127 and 8, respectively

  4. D

    255 and 7, respectively

Show answer

Correct answer

  • A

    255 and 8, respectively

Question 5

+3 marksOne correct option

Consider a Binary Search Tree (BST) containing distinct keys. Each node of the BST is defined using the following class:

The following recursive functions are applied by calling , where points to the root of the BST. Which of the following implementations will print the keys of the BST in strictly decreasing order?

Consider a Binary Search Tree (BST) containing distinct keys. Each node of the BST is defined using the following class:
  1. A
    Figure from the original question paper
  2. B
    Figure from the original question paper
  3. C
    Figure from the original question paper
  4. D
    Figure from the original question paper
Show answer

Correct answer

  • D
    Figure from the original question paper

Question 6

+3 marksOne correct option

Suppose the letters {a, b, c, d, e} occur with the following frequencies.

How many bits will be used to encode the letter b in the Huffman code for this alphabet?

Suppose the letters {a, b, c, d, e} occur with the following frequencies.
  1. A

    1

  2. B

    2

  3. C

    3

  4. D

    4

Show answer

Correct answer

  • B

    2

Question 7

+3 marksOne correct option

Consider a set of activities , where each activity has: • a processing time (time required to complete the activity), and • a deadline . Only one activity can be executed at a time. If an activity finishes at time , the next activity can start at time itself. Assume that the initial start time is 0. The lateness of an activity is defined as:

where denotes the finish time of activity . Let denote the maximum lateness among all activities: The objective is to schedule the activities in an order that minimizes . Which of the following greedy strategies will always produce an optimal schedule for minimizing the maximum lateness ?

Consider a set of activities  , where each activity  has: • a processing time  (time required to complete the activity),
  1. A

    Always schedule first the activity with the minimum processing time.

  2. B

    Always schedule first the activity with the earliest deadline.

  3. C

    Always schedule first the activity with the minimum value of .

  4. D

    Always schedule first the activity with the maximum processing time.

Show answer

Correct answer

  • B

    Always schedule first the activity with the earliest deadline.

Question 8

+3 marksOne correct option

In a list , two elements and form a significant inversion if The total number of significant inversions for is ___.

  1. A

    3

  2. B

    4

  3. C

    5

  4. D

    6

Show answer

Correct answer

  • C

    5

Question 9

+3 marksOne correct option

Consider the Quick Select algorithm for finding the smallest element in an input list of size containing distinct elements. The algorithm uses the Median of Medians (MoM) technique to select the pivot element. Which of the following is the correct recurrence relation representing the worst-case running time of this Quick Select algorithm?

  1. A

    —

  2. B

    —

  3. C

    —

  4. D

    —

Show answer

Correct answer

  • B

    —

Question 10

+3 marksOne correct option

Consider the following strategy to solve a problem of input size . Divide the problem into sub-problems, each of size , where the time required to perform this division is proportional to the input size (i.e., ). The number of steps required to combine these 6 solutions is . We apply this strategy recursively till the sub-problems can not be further divided into sub-problems. What will be the nearest upper bound for the above algorithm?

  1. A

    —

  2. B

    —

  3. C

    —

  4. D

    —

Show answer

Correct answer

  • A

    —

Question 11

+3 marksOne or more correct options

Let be a connected complete graph with 4 vertices and 6 edges, where all edge weights are distinct and ordered as: Which of the following sets of edges can be in a minimum cost spanning tree of ? (Select all that apply.)

Select all that apply.

  1. A

    —

  2. B

    —

  3. C

    —

  4. D

    —

  5. E

    —

Show answer

Correct answers

  • A

    —

  • D

    —

Question 12

+3 marksOne or more correct options

Consider a min-heap implemented using an array with distinct elements. Which of the following statements about the time complexity of operations on a min-heap is/are true in the worst case?

Select all that apply.

  1. A

    Inserting a new element into a min-heap can be performed in time.

  2. B

    Finding the second minimum element in a min-heap can be performed in time.

  3. C

    Finding the maximum element in a min-heap can be performed in time.

  4. D

    Deleting the minimum element from a min-heap can be performed in time.

Show answer

Correct answers

  • A

    Inserting a new element into a min-heap can be performed in time.

  • B

    Finding the second minimum element in a min-heap can be performed in time.

Question 13

+4 marksWritten answer

Consider the given weighted adjacency matrix for a complete undirected graph with vertex set {0, 1, 2, 3, 4}. Where in the matrix is the weight of the edge .

What is the total weight of the minimum spanning tree(MST) for the given graph?

Consider the given weighted adjacency matrix  for a complete undirected graph with vertex set {0, 1, 2, 3, 4}. Where  in
Show answer

A written answer, not marked automatically.

Question 14

+4 marksWritten answer

In the table below, we have 9 activities with the corresponding start and finish times. It might not be possible to complete all the activities since their time frames can conflict. For example, if any activity starts at time 0 and finishes at time 4, then other activities can not begin before 4. It can be started at 4 or later. What is the maximum number of activities which can be performed without conflict?

In the table below, we have 9 activities with the corresponding start and finish times. It might not be possible to comp
Show answer

A written answer, not marked automatically.

Question 15

+3 marksWritten answer

An AVL tree contains 120 nodes. What is the maximum possible height of the AVL tree? Assume that the height of an empty AVL tree is 0 and the height of an AVL tree with a single node is 1

Show answer

A written answer, not marked automatically.

Question 16

+3 marksWritten answer

Consider the following function

What median value will be returned by the given function for the following list?

Consider the following function
Consider the following function
Show answer

A written answer, not marked automatically.