CACSC02
CACSC02
of Pages: 4
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”);
}
}
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.
(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.
//Initialization
for j = 0… N-1 {visited [j] = 0; parent [j] = -1 ; }
(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---------