Question 1
What is , given the definition of above?

The IIT Madras BS Programming, Data Structures and Algorithms using Python (PDSA) Quiz 1 paper sat on 15 Mar 2026, in the January 2026 term: 17 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.
What is , given the definition of above?
A written answer, not marked automatically.
Consider the following implementation for selection sort:
Suppose a list is used as an input parameter to the above selection sort. How many times will the condition evaluate to true?
A written answer, not marked automatically.
Suppose each node of the linked list is an object of class Node. Variable head points to the first node of the linked list, and the list initially contains the following elements: 8 → 3 → 6 → 1 → 9 → 4 → 7 Consider the following function:
What will be the output of the given function if it is called on the head node of the given linked list?
A written answer, not marked automatically.
Linear probing is an open addressing scheme for resolving hash collisions in tables. Linear probing takes the original hash index and increments the value by 1 until a free slot is found. A hash table contains 8 buckets indexed from 0 to 7 and uses linear probing to resolve collisions. The hash function used is: The following keys are inserted into the hash table in the given order: 18, 10, 12, 21 After all these insertions, the key value 42 is inserted. At which index will the key 42 be placed?
A written answer, not marked automatically.
A directed acyclic graph has 6 vertices. If it is guaranteed to have a unique topological sort, what is the maximum number of edges this graph can have?
A written answer, not marked automatically.
Consider the following functions: • • • Which of the following is/are false?
—
—
—
—
Correct answers
—
—
Consider the following implementation of Merge Sort:
Which of the following is/are true about Merge Sort?
The function preserves the relative order of equal elements.
The worst-case time complexity of is .
The best-case time complexity of is .
Replacing with in the condition of the function will make the algorithm unstable.
Correct answers
The function preserves the relative order of equal elements.
The worst-case time complexity of is .
Replacing with in the condition of the function will make the algorithm unstable.
Which of the following statements is/are true about the Quicksort algorithm? Assume that the first element of the list is always chosen as the pivot.
If the input list is already sorted in ascending order, the time complexity will be .
If the input list is already sorted in descending order, the time complexity will be .
It is a stable sorting algorithm.
The average-case time complexity is .
Correct answers
If the input list is already sorted in ascending order, the time complexity will be .
The average-case time complexity is .
Consider a singly linked list implemented using the above class. Assume that: • variable points to the first node of the linked list, • variable points to the last node of the linked list, • the linked list contains nodes where , Which of the following operations cannot be guaranteed to run in constant time?
Inserting a new node at the front of the linked list.
Inserting a new node at the end of the linked list.
Deleting the first node of the linked list.
Deleting the last node of the linked list.
Accessing the second last node of the linked list.
Correct answers
Deleting the last node of the linked list.
Accessing the second last node of the linked list.
Which of the following is/are possible degree sequence(s) of the vertices of a connected undirected graph with five vertices? Note: Degree sequence is a series of positive integers where each is the degree of the vertex of the graph.
—
—
—
—
—
Correct answers
—
—
—
Which of the following statement(s) is/are true about Breadth First Search (BFS) in an unweighted graph ?
BFS goes deep along a path before visiting all neighbors at the same level.
BFS can be used to find the shortest path in a weighted graph with arbitrary positive edge weights without any modification in graph.
BFS uses a queue to keep track of vertices to be explored.
BFS traversal depends on the choice of the starting vertex.
BFS explores all neighbors of a vertex before moving to vertices at the next level.
Correct answers
BFS uses a queue to keep track of vertices to be explored.
BFS traversal depends on the choice of the starting vertex.
BFS explores all neighbors of a vertex before moving to vertices at the next level.
You are given a non-empty list of integers sorted in ascending order. Every element in the list appears exactly twice, except for one element that appears only once. For example, the list may look like , where the element 3 appears only once. What is the time complexity of the most efficient algorithm to find the element that appears only once?
—
—
—
—
Correct answer
—
You are implementing binary search on a sorted list L that may contain duplicate values. You need to find the index of the last occurrence of X . If an instance of X is found at L[mid] , how should the search proceed to find the last possible occurrence?
Store mid as a potential answer and continue searching in the left subarray by setting high = mid - 1 .
Immediately return mid , as binary search on a sorted array with duplicates will always find the last occurrence if multiple exist.
Store mid as a potential answer and continue searching in the right subarray by setting low = mid + 1 .
Discard mid and search both the left ( high = mid - 1 ) and right ( low = mid + 1 ) subarrays recursively.
Correct answer
Store mid as a potential answer and continue searching in the right subarray by setting low = mid + 1 .
Let be a stack and be a queue supporting the following operations: Assume that supports the standard stack operations and , and supports the standard queue operations and . Suppose the initial state of the queue where 12 is at the front and 18 is at the rear, and the stack S is empty initially. The following sequence of operations is performed:
After performing the given sequence of operations, what will be the front and rear elements in queue Q?
—
—
—
—
Correct answer
—
For a connected undirected graph with 7 vertices, which of the following gives the correct minimum and maximum possible number of edges?
Min: 5 , Max: 21
Min: 6 , Max: 20
Min: 6 , Max: 21
Min: 7 , Max: 21
Correct answer
Min: 6 , Max: 21
Let G be a connected undirected graph with n vertices represented using an adjacency matrix. In the DFS implementation given below, assume that checking whether a vertex has already been visited takes time.
What is the tightest upper bound for the worst case time complexity of DFS?
—
—
—
—
Correct answer
—
Select the most appropriate data structure for the following operations:
1 - ii, 2 - i, 3 - iii, 4 - iv
1 - ii, 2 - i, 3 - iv, 4 - iii
1 - i, 2 - iii, 3 - ii, 4 - iv
1 - iii, 2 - ii, 3 - i, 4 - iv
Correct answer
1 - ii, 2 - i, 3 - iii, 4 - iv