0% found this document useful (0 votes)
18 views11 pages

Dsa Compre Paper 2

Uploaded by

yuvraj9152
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
18 views11 pages

Dsa Compre Paper 2

Uploaded by

yuvraj9152
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 11

Birla Institute of Technology & Science, Pilani

Online B.Sc. Computer Science Programme


First Semester 2023-2024

Comprehensive Exam
(Slot-2)

Course No. : BCSZC311


Course Title : Data Structure and Algorithms
Nature of Exam : Open Book
Weightage : 50% [50 Marks]
Duration : 2 Hours 30 Minutes
Date of Exam : 13 January,2024
Instructions for students:
1. Write your name and ID on every page of your submission. Pages not containing this will not be evaluated.
2. Some questions have internal options between parts (A) and (B). Only one of (A) or (B) needs to be answered
in this case. Whenever a question has options, it is explicitly mentioned in the question statement. All of the
sub-questions numbered (i), (ii), … within a question do need to be answered.
3. Parts of the same question should be answered consecutively. Attempt every new question on a fresh page.
Mention the correct question and subquestion numbers for each answer.
4. Please ensure your submission is clear and legible. Marks will not be awarded for unclear and illegible
answers.
5. Assumptions made, if any, should be stated clearly at the beginning of your answer.
6. Wherever a question mentions restrictions (“one word only”, “one sentence only”, or a blank to be filled),
please adhere to them strictly.
7. While you are allowed to either type in your answers or scan them, some questions will be more convenient to
answer on paper than by typing. Choose the mode in which you answer carefully to avoid wasting time.
8. Not following any of the mentioned instructions WILL incur a penalty.
9. Do not panic. Even the toughest questions can be cracked with enough patience. All the best!

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

(A) Answer the questions given below:


(i) f(n) = Ω(g(n)) if ∃ constants c1 and n0 such that _________(a)__________ ∀ ___(b)___. Fill
in the blanks for (a) and (b). [1+1 = 2 marks]

(ii) If g(n) = n5 + 2024n3log2n + 42n4, then g(n) ∈ O(___). Fill in the blank.
[1 mark]

(iii) Consider the C program given below:


for (int i = 0; i < n; i++)
{
for (int j = 0; j < n; j++)
{
for (int k = 0; k < n; k = k*2)
{
printf(“%d, %d, %d\n”, i, j, k);
}
}
}
Calculate the worst-case time complexity of this program. Justify the time complexity
you arrived at in your answer. [4 marks]

(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:

for (int i = 0; i < n; i++)


{
for ( ; i > n; i++);
for ( ; i < n; i++);
for (int j = i; j > i + 1; j--);

for (int j = 0; j < n*n; j = 2*j)


{
for ( ; j < n*n*n; j = 3*j);
}
}

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):

a. deleteFirst(): delete the element at the head of the linked list,


b. insertLast(): insert an element at the tail of the linked list,

(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:

234, 231, 342, 332, 632, 924, 4, 71, 672, 43 [5 marks]


Q.6. (i) Consider the hash functions: h1(i) = (i4+25i2+29) mod n and h2(i) = (i + 1) mod n,
where n = 11 is the size of a hash table.

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.

11, 12, 14, 13, 15, 16, 18, 17, 19, 20

Illustrate the final resulting table. [3 Marks]

(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.)

(A) Consider the following AVL tree:

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

(B) Consider the graph given below:


Apply Kruskal's algorithm on the following graph and find the Minimum Spanning
Tree. Break ties (if any) arbitrarily. Show the algorithm stepwise, showing the state of the
data structures used at each iteration. Illustrate the final minimum spanning tree by
drawing it.
[4 + 1 marks]
Q.8. Consider several cities in a country, and assume that these cities are connected by
one-way highways. Each highway imposes a limit/threshold on the weight of trucks
passing through it. For a given highway h, let w(h) denote the threshold imposed by h on
the weight of a truck.

Highway source Highway Destination Capacity

Ahmedabad Bengaluru 5 tonnes

Bengaluru Chennai 5 tonnes

Chennai Ahmedabad 3 tonnes

Ahmedabad Delhi 3 tonnes

Chennai Delhi 2 tonnes

Chennai Ernakulam 4 tonnes

Ernakulam Bengaluru 1 tonne

Delhi Ernakulam 2 tonnes

Delhi Faridabad 6 tonnes

Faridabad Gurugram 9 tonnes

Ernakulam Gurugram 1 tonne

(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]

You might also like