0% found this document useful (0 votes)
32 views4 pages

CACSC02

Uploaded by

donotreply
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)
32 views4 pages

CACSC02

Uploaded by

donotreply
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/ 4

Total No.

of Pages: 4

NETAJI SUBHAS UNIVERSITY OF TECHNOLOGY


B. Tech. - II Semester
Open Book Exam - July 2020
Course Code: CACSC02 Course Title: Data Structures
Max. Marks: 25
Time: 2 Hrs (for Writing Answers) + 30 Mins (Download Question Paper, Scan & Upload Answer Script)
Note:
❖ There are 8 questions. Each question is of equal marks. Student may attempt any 5 question.
❖ Students must answer the questions in the same order as listed in the question paper.
❖ Students must use A4 size sheets to write the answers and must number each page at Top Right
Corner in a clearly readable form. Each of the A4 size sheet used must be signed by the student at
the Bottom Right in a clearly readable form.
❖ Students must scan all the pages of their answer scripts and duly filled in undertaking form using
a scanning App (like Adobe Scan) to create a PDF file. Students must upload this PDF file on the
Google classroom / on any other platform as suggested by the Chairperson, CCC.
❖ After uploading their answer script, Students must scan all the pages used for rough work in a
separate PDF file and keep it ready with them so as to submit immediately to the Chairperson,
CCC as and when asked. Students should retain the physically written answer script pages & rough
work pages securely. The students may be required to submit these to Chairperson, CCC after the
university gets opened for physical presence of the students.
❖ Missing data / information, if any, maybe suitably assumed & mentioned in the answer.

Q. No. Question Marks

1 void bubblesort(int a[], int n) {


2 int swapped = 1;
3 while(swapped) {
4 swapped = 0;
5 for(i=0; i<= n-1; i++) {
6 if(a[i+1] <= a[i]) {
7 // assume that swap function is available
8 swap(a[i], a[i+1]);
1.a 3
9 swapped = 1;
10 }
11 }
12 }
13 }

Above function is a variant of Bubble Sort. The input array to this function may
contain an element multiple time. The function has been written to sort the array
in ascending order in time O(n2). However, there is a bug in it………..
a) Which line has the bug and how can it be fixed?
b) If this bug is not removed, how will this function behave? Explain your answer
by taking suitable input of 8 elements

What is the time complexity of running the following nested loop? Show your
work.
for (i = 1; i <= n; i++) {
1.b for (j = 1; j <= n; j = j+i) { 2
printf(“Hello\n”);
}
}

Suppose we want to encode a text having characters [ a, b, c, d, e, f, g ] occurring


with the following frequencies

Character a b c d e f g
Frequency 36 22 29 15 33 18 7
2 5
(i) Assign each of the character a different fixed length code of minimum size.
Compute the number of bits required to represent the text in binary.
(ii) Now, compute the variable length code using Huffman Coding technique for
each of the character. Compute the saving in terms of number of bits required
to represent the text in binary.

Draw an Expression Tree for the following expression:


3.a ( ( a + b ) ^ 3 ) – 3 * a * b ) / ( ( a + b ) ( a – b ) ). From the expression tree, derive 3
the (i) Prefix Expression and (ii) Postfix Expression

What is the average number of comparisons needed in a search to determine the


position of an element in an array of 128 elements, if the elements are
3.b 2
(i) ordered from smallest to largest
(ii) unordered

(i) A programmer is writing program for developing a text editor very similar to
Microsoft Word. Which data structure should he opt to implement an "undo"
feature? Justify.

(ii) Indigo Airline has developed a booking system that maintains a wait-list of
passengers on a flight who are waiting for an upgrade to first class. To give incentive
4.a to frequent flyers, passengers are upgraded to a first-class seat when it becomes 3
available based on the number of flights a passenger has taken. Which data structure
Airline must have implemented in their system? Justify.

(iii) What is the minimum number of comparisons needed to find the maximum
element in a binary min-heap having 1023 elements assuming heap is implemented
in an array? Justify your answer.
An array-based tree structure contains 74 nodes. Assume that the array index starts
at 0.
(i) What is the index of the first leaf node?
4.b 2
(ii) Which index node is the parent of a node at index 55?
(iii) Which index are the children of node at index 24?
(iv) How many leaf nodes are there in the tree?

Show the step by step construction of a Binary Tree structure whose Preorder
Traversal and Postorder Traversal are as given below: (No need to write code)
5.a Preorder: 25, 35, 42, 38, 30, 15, 29, 16, 8, 47 3
Postoder: 42, 30, 38, 35, 16, 8, 29, 47, 15, 25

Draw the step by step Min Heap structure obtained from inserting the 24, 29, 23, 27,
5.b 22, 25, 28, 26 in this order and then calling deleteMin twice on the obtained Min 2
Heap. (Please note that Heap is to be drawn in form of a Binary Tree not as an Array)

Show step by step construction of an AVL Tree that is obtained from inserting the
following values: 13, 19, 12, 17, 14, 15, 18. If an insertion causes the tree to become
6.a 3
unbalanced, then perform and explain the type of rotation required to maintain the
balance.

Show the step by step construction of a Binary Search Tree structure for the given
6.b Postorder traversal: 25, 20, 36, 40, 32, 62, 60, 74, 65, 52 (No need to write algorithm 2
/ code)

Name the two different approaches implement a priority queue. Compare these on
7.a 1
the basis of time required for Enqueue and Dequeue operations.

Can a linear search be more efficient than binary search to find an element in an
7.b 1
array?

There are two approaches for finding the nth Fibonacci number: Recursive Method
7.c and Iterative Method. Comment on the Big-O time complexity of the two 1
approaches.

Quick Sort Algorithm is used to sort 8 numbers in ascending order using the first
element as pivot. When the input is (1, 2, 3, 4, 5, 6, 7, 8) it performs C1 comparisons.
7.d 1
However, when input is (4, 6, 1, 3, 8, 5, 2, 7) it might perform C2 comparisons.
Comment on the relation between C1 and C2 with proper justification.
A graph can be represented using two approaches. Compare these on the basis of
7.e memory required to store graph information, connectivity density in the graph and 1
easiness to find adjacent vertices.

Following is the Pseudocode of Depth First Traversal of Graph

//Initialization
for j = 0… N-1 {visited [j] = 0; parent [j] = -1 ; }

function DFS(i) // DFS staring from vertex i


{ //Mark I as visited
8 5
visited[i] = 1 ;
// Explore each neighbor of I recursively
for each (I, j) in E // Set E contains all edges of graph
{
if (visited[j] == 0)
{
parent[j] = I ;
DFS(j) ;
}
}
}

(a) Represent the above shown graph in the adjacency matrix form.
(b) Show the status of visited array, parent array when the above written DFS
function runs from vertex i = 0. Explain the functioning of this algorithm for each
edge (i, j) as derived from Adjacency Matrix.

----------X----------X---------

You might also like