Question 1
Consider the following function:
If the function is called as: What value will the function return?

The IIT Madras BS Programming in Python (Python) End Term paper sat on 10 May 2026, in the January 2026 term, set 2: 24 questions for 52 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.
Consider the following function:
If the function is called as: What value will the function return?
A written answer, not marked automatically.
In a binary tree, the total number of nodes is 28. It is known that 10 nodes have exactly two children. How many nodes have exactly one child?
A written answer, not marked automatically.
While inserting the elements 60, 30, 50, 55, 80, 90, 65, 70, and 10 into an empty binary search tree (BST) in the sequence shown, the sum of elements at maximum depth is __.
A written answer, not marked automatically.
An entire message is created using characters from the set The probability of occurrence of each character is given in the table below.
How many bits will be used to encode the message ABCDE using Huffman codes?
A written answer, not marked automatically.
In a list , two elements and form a significant inversion if and . The total number of significant inversions for is ___ .
A written answer, not marked automatically.
Arrange the above functions in increasing order of asymptotic complexity.
—
—
—
—
Correct answer
—
A list of strings, each of length is sorted in lexicographical order using the Merge Sort algorithm. What is its time complexity? (Assume that comparing strings lexicographically takes )
—
—
—
—
Correct answer
—
Consider that Quick sort is applied on a list of size which is sorted in reverse order . What will be the asymptotic running time of Quick sort if the pivot is taken to be First element Last element Choose the correct option corresponding to the correct pair of complexities for both pivots.
and
and
and
and
Correct answer
and
Consider the following class :
Consider an implementation of a linked list where each node is created using the given class . Suppose it has a variable that points to the first node of the linked list.
Suppose we want to perform the following operations on the linked list containing nodes: Insertion of a new node at the first position of the linked list1. Insertion of a new node at the last position of the linked list2. Deletion of the first node of the linked list3. Deletion of the last node of the linked list4. Using the most efficient algorithm, which of the following options correctly represents the time complexity of the above operations respectively?
—
—
—
—
Correct answer
—
Consider the following undirected graph .
Run BFS starting from vertex A. If multiple adjacent vertices exist, they are visited in alphabetical order. Which of the following is the correct BFS traversal order?
A, B, D, E, C, F, G, H, I, J
A, B, D, E, F, C, G, H, I, J
A, B, C, H, J, G, D, E, F, I
A, B, D, E, C, F, H, G, I, J
Correct answer
A, B, D, E, C, F, G, H, I, J
Consider a connected, directed graph on which DFS is executed. and numbering is used in the DFS algorithm on the graph. In which of the following situations can we conclude that the edge is a cross edge?
—
—
—
—
Correct answer
—
The Bellman-Ford algorithm cannot be used if a graph has negative cycles. This is because:
The algorithm only runs for n iterations, where n is the number of vertices.
The notion of the shortest path is not well-defined if there are negative cycles.
Dealing with negative cycles requires examining all paths exhaustively, which takes exponential time.
To handle negative cycles, we need to compute all-pairs shortest paths.
Correct answer
The notion of the shortest path is not well-defined if there are negative cycles.
While inserting the elements 8, 4, 1, 3, 9, 2, and 11 in an empty AVL tree in the given sequence, the leaf elements are__.
1, 3, 8, 11
1, 3, 9, 11
2, 3, 9, 11
1, 2, 8, 11
Correct answer
1, 3, 8, 11
Consider the following activities .
We can execute one activity at a time. Each activity has activity duration , which represents the time required to complete, and a deadline . Consider the initial start time to start the first selected activity. Let the lateness of a schedule be the maximum amount by which any single activity is late in that schedule. What is the minimum lateness across all possible schedules?
2
3
4
5
Correct answer
4
Consider the following recurrence relation for an algorithm: with base case . The complexity of this algorithm is ___
—
—
—
—
Correct answer
—
Consider four matrices and of dimensions and respectively. If and , then which of the following takes the least time for computation?
—
—
—
—
Correct answer
—
Assume there are teachers and 2n subjects. Each teacher has to teach exactly 2 subjects. Their preferences are modelled as a directed graph , such that there exists an edge from a teacher node to a subject node in , if prefers teaching . How can this problem be modelled as a network flow problem?
It can be modelled as a network flow problem, where the source node is connected to every teacher node in with capacity of n, and every subject node in is connected to the sink node with capacity of 2n.
It can be modelled as a network flow problem, where the source node is connected to every teacher node in G, and every subject node in is connected to the sink node. All edges in the network flow graph have equal capacity.
It can be modelled as a network flow problem, where the source node is connected to every teacher node in with capacity of 2, and every subject node in is connected to the sink node with capacity of 1.
It can be modelled as a network flow problem, where the source node is connected to every teacher node in with capacity of 1, and every subject node in is connected to the sink node with capacity of 2.
Correct answer
It can be modelled as a network flow problem, where the source node is connected to every teacher node in with capacity of 2, and every subject node in is connected to the sink node with capacity of 1.
A factory produces two types of gadgets A and B. The profit earned is Rs. 6 per unit of A and Rs. 4 per unit of B. Each gadget must be processed on two machines M and N. One unit of A requires 2 minutes on machine M and 1 minute on machine N.• One unit of B requires 1 minute on machine M and 2 minutes on machine N.• Machine M is available for 6 hours (360 minutes) per day and machine N is available for 7 hours (420 minutes) per day. Which of the following is the correct Linear Programming formulation to maximize profit? Let be the number of units of type A and be the number of units of type B.
Maximize: Subject to:
Maximize: Subject to:
Maximize: Subject to:
Maximize: Subject to:
Correct answer
Maximize: Subject to:
Let G be a simple graph with 25 vertices and 50 edges. The size of the minimum vertex cover of G is 10. What is the size of the maximum independent set of G ?
65
90
15
35
Correct answer
15
A hash table of size 10 uses open addressing with linear probing and the hash function After inserting 6 keys into an empty hash table, the final table is:
Which of the following could be possible insertion orders that produce this table?
21, 32, 27, 12, 31, 40, 25
21, 32, 27, 12, 25, 31, 40
40, 32, 21, 25, 31, 12, 17
40, 32, 21, 25, 31, 27, 12
Correct answers
21, 32, 27, 12, 31, 40, 25
40, 32, 21, 25, 31, 27, 12
A technology training institute offers an advanced certification program consisting of 10 modules. The program is divided into terms of 4 months. Students may enroll in any number of modules in a term, but a module can only be taken after completing all of its prerequisite modules. The prerequisite structure is given below.
There is no restriction on the number of modules a student can take in a term. The minimum number of terms required to complete all 10 modules is ___.
A written answer, not marked automatically.
There are stones, numbered . For each , the height of Stone is . There is a frog who is initially on Stone . He will repeat the following action some number of times to reach Stone If the frog is currently on stone , it can jump to Stone or Stone . Here, a cost of is incurred, where is the stone to land on. Find the minimum possible total cost to reach stone 5 from stone 0 for the following sequence of heights for 6 stones.
A written answer, not marked automatically.
Consider the following graph.
Which of the following options correctly represents the shortest distances from node 0 to nodes (1, 2, 3, 4, 5) respectively?
3, 2, 5, 9, 8
4, 2, 6, 9, 8
3, 2, 5, 8, 7
3, 2, 5, 7, 8
Correct answer
3, 2, 5, 8, 7
Consider the graph G given below.
Let Minimum Spanning Trees (MSTs) of the graph be constructed using algorithms such as Kruskal’s or Prim’s algorithm. Which of the following statement(s) is/are correct?
The total weight of every MST is 10
The total weight of every MST is 11
The edge (d, e) will not be part of any MST
The edge (b, e) will be part of every MST
The number of distinct MSTs in the graph is 2
Correct answers
The total weight of every MST is 10
The edge (d, e) will not be part of any MST
The edge (b, e) will be part of every MST