Dsa Compre Paper 2
Dsa Compre Paper 2
Comprehensive Exam
(Slot-2)
Q.1. Attempt ANY ONE out of questions (A) and (B) below. You may choose to answer
ONLY (A) and NOT (B). Or, you may attempt ONLY (B) and NOT (A). Question 1 is
worth 8 marks in total. (There are NO bonus marks for answering both questions.)
(ii) If g(n) = n5 + 2024n3log2n + 42n4, then g(n) ∈ O(___). Fill in the blank.
[1 mark]
(iv) State whether the following statement is True or False: “O(log2n) ≠ O(log4n). In
other words, O(log2n) and O(log4n) do not refer to the same set.”
[1 mark]
OR
(B) Answer the questions given below:
(i) What is the most optimal worst-case time complexity of inserting an element into a
heap of N elements? [1 mark]
(ii) What is the most optimal worst-case time complexity of finding the minimum
element in a min-heap of N elements? [1 mark]
(iii) What is the worst-case time complexity of heap sort? What is its worst-case space
complexity? Justify both your answers in 1-2 short sentences. [1.5 + 1.5 = 3 marks]
(iv) Discuss briefly how tries can be used to achieve optimal compression of a text file.
Answer in no more than 2-3 sentences.
[3 marks]
Q.2. (i) Consider the following C program:
Find the worst-case time complexity of the above program and express your answer in
terms of Big-Oh notation. Justify the time complexity you arrived at in your answer.
[4 marks]
(ii) Arrange the following functions in increasing order of their worst-case time
complexities:
f1(n) = 2logn
f2(n) = nlog2n
f3(n) = 2n
f4(n) = n3
f5(n) = n2logn
[Note: Simply write the correct increasing ordering (eg., a < b < c). Do not write anything
else in the answer. This question (Q2(ii)) has binary marking (you will either get 4 marks
or 0 marks).] [2 marks]
Q.3. Recall the implementation of linked lists taught in the course. It consists of two structs:
LIST and NODE. LIST is the overarching structure of a linked list, whereas NODE is the
structure of a node in the linked list. These two structs can have various attributes, giving
rise to different types of linked lists. You are given five different kinds of linked lists
[enumerated in sub-questions (i) through (v)]. In each case, you need to write the
worst-case time complexity of the following two different operations in their most
efficient implementations (you have to come up with these on own own, although there is
no need to write the implementations):
(i) The linked list structure has a head node but no tail node. The nodes have both next
pointers and previous pointers.
(ii) The linked list structure has a head node and a tail node. The nodes have previous
pointers only and no next pointers.
(iii) The linked list structure has a tail node but no head node. The nodes themselves only
have next pointers and no previous pointers.
(iv) The linked list structure has a head node and a tail node. The nodes themselves have
both next pointers and previous pointers.
(v) The linked list structure has no head node and no tail node. The nodes themselves have
both next and previous pointers.
[Note: Take n to denote the length of the linked list. This question may be appropriately
answered in a tabular format.] [5 * 2 * 0.5 = 5 marks]
Q.4. (i) You want to build an application that holds a sequence in which you want to be able to
access any element without scanning (ie., in O(1) time). Further, you also want to be able
to do binary search on the sequence (ie., you want to search any element in O(logn) time).
Which underlying data structure will you choose for your application and why? Explain in
brief. [1 + 2 = 3 marks]
(ii) Perform insertion sort (in descending order) on the following array of numbers:
16, 1, 8, 65536, 256
Show the state of the array after each iteration of the insertion sort routine.
[3 marks]
Q.5. (i) A research paper has recently proposed a new comparison-based sorting algorithm that
claims to have a time-complexity of O(n log(log(n))). Is this possible? (Answer in
Yes/No). Why or why not? (Reason in a few lines.) [1 mark]
(ii) Apply straight radix sort (based on decimal digits from least significant bit [LSB] to
most significant bit [MSB]) on the following list of numbers. Show the state of the list
after each iteration of the sorting routine:
Insert the elements in the following order into the given hash table using open addressing
with double hashing for handling collisions. Here, h1 is to be used for the probe and h2 is
to be used for the offset. Assume that the table was empty before insertion.
(ii) Given the following in-order traversal of a binary tree, draw all possible trees that it
can represent:
1, 2, 3, 4
[Note: Do not try typing this. Draw, scan/photograph and upload.] [3 Marks]
Q.7. Attempt ANY ONE out of questions (A) and (B) below. You may choose to answer
ONLY (A) and NOT (B). Or, you may attempt ONLY (B) and NOT (A). Question 7 is
worth 5 marks in total. (There are NO bonus marks for answering both questions.)
Perform the following operations on the AVL tree (in sequence) and depict the state of
the AVL tree after each operation in your answer. You may need to perform several
rotations, but those need not be shown in your answer. Show ONLY the sequence of
states of the AVL tree (which means your answer should have five drawings, one for each
operation). There is no need to provide explanations or justifications for the rotations or
transformations.
a. Insert 2023
b. Insert 4096
c. Insert 69
d. Delete 6553
e. Delete 23
[Note: You know that there are two variants of the deletion algorithm - one which replaces
the node with the successor and one which replaces it with the predecessor. For this
question, replace it with the predecessor.]
[1*5 = 5 marks]
OR
(i) Model this situation as a graph. Make suitable choices for what the nodes and edges
represent. Decide whether the edges should be weighted/unweighted, directed/undirected, etc..
Draw the graph that you have modelled for the above data. [4 marks]
(ii) Dijkstra's single source shortest path algorithm as covered in the course is given as
follows.
Develop an algorithm by modifying the above algorithm to find the heaviest truck that can be
sent from a given source to a given destination. Underline the minimal changes that you make
to the above algorithm. Write the entire modified algorithm down ensuring that it applies to
your graph model. [4 marks]