Fundamentals of Data Structure - Algorithms (Info 2101)
Fundamentals of Data Structure - Algorithms (Info 2101)
(b) The inorder and preorder traversals of a binary tree T yield the following B.TECH/IT/3RD SEM/INFO 2101/2019
sequence of nodes:
Inorder : U K M E A L F J Z G
FUNDAMENTALS OF DATA STRUCTURE & ALGORITHMS
Preorder : A K U E M Z F L J G (INFO 2101)
Draw the tree T. State briefly the logic used to construct the tree. Time Allotted : 3 hrs Full Marks : 70
6 + 6 = 12
Figures out of the right margin indicate full marks.
7. (a) Consider the following graph for DFS traversal. Starting from node 0, Candidates are required to answer Group A and
what will be DFS traversal? Show every step . any 5 (five) from Group B to E, taking at least one from each group.
Candidates are required to give answer in their own words as far as practicable.
Group – A
(Multiple Choice Type Questions)
(b) What is Adjacency matrix and Adjacency list of the above graph? 1. Choose the correct alternative for the following: 10 × 1 = 10
(c) What is the critical node in AVL tree? Explain with example. (i) The time complexity of 4 algorithms that solves the same task is given
5 + (2 + 2) + 3 = 12 below. Which algorithm will execute the slowest for large values of n
(a) O(n2) (b) O(n)
Group – E (c) O(2n) (d) O(nlog n).
(ii) In a modified Towers of Hanoi problem, you have to move 5 disks from peg
8. (a) Transform the array 2, 8, 10, 6, 15, 12, 11 into a heap using any suitable
1 to peg 3. To do that first you need to move 4 disks from peg 1 to peg 2.
method and use the heap to sort the array. Show all intermediate steps.
How many legitimate moves will it take to move 4 disks from peg 1 to peg 2?
(b) Using divide-and-conquer approach, write the quick sort algorithm and (a) 31 (b) 16
derive its complexity. (c) 32 (d) 15.
6 + 6 = 12
(iii) The prefix expression of the infix expression a * (b +c) / e - f
(a) /*a+bc-ef (b) -/*a+bcef
9. (a) Write a function to implement Binary search algorithm. Assume the user
(c) -/*+abcef (d) none.
is going to enter the list of integers in either ascending or descending
order. (iv) A circular queue is empty if
(a) front=rear-1 (b) rear=front-1
(b) A hash function f defined as f(key) = key mod 7, with linear probing, is
(c) front=rear+1 (d) none.
used to insert the keys 37, 38, 72, 48, 98, 11, 56 into a table indexed from
0 to 6. What will be the location of key 11? Show your work. What is (v) The following sequence of operations is performed on stack. push(1),
quadratic probing? push(2), pop(), push(1), push(2), pop(), pop(), pop(), push(2), pop(). The
sequence of popped out values are
(c) (i) In insertion sort algorithm, how many times the outer for loop will
(a) 2,2,1,1,2 (b) 2,2,1,2,2
iterate when n = 100?
(c) 2,1,2,2,1 (d) 2,1,2,2,2.
(ii) In insertion sort, at some point you are trying to insert kth element
where 0 < k < n. Assume also you started with a file which was sorted (vi) Using Bubble sort, to sort 100 names, the maximum number of
in reverse order. What will be the exact number of key comparisons? comparisons will be
6 + 3 + (1 + 2) = 12 (a) 4950 (b) 5050
(c) 10000 (d) 100.
(vii) The inorder and postorder traversal of a binary tree are DBEAFC and DEBFCA. Group – C
What will be the total number of nodes in the left subtree of the given tree?
(a) 1 (b) 4 (c) 5 (d) none. 4. (a) Consider the following queue of characters, where QUEUE is a circular
queue with a size of 6. At some point, FRONT=2, REAR=4 and QUEUE: _ ,
(viii) What data structure is used for breadth first traversal of a graph?
A,C,D, _ , _
(a) queue (b) stack
Here “_” denotes an empty cell in the array. What will be the value of
(c) linked list (d) none of the mentioned.
FRONT and REAR, also describe the QUEUE as the following operations
(ix) If a node having two children is deleted from a binary tree, it is replaced by its takes place.
(a) inorder predecessor (b) inorder successor (a) F is added to the queue (b) Two letters are deleted
(c) preorder predecessor (d) none of the above. (c) K,L and M are added to the queue (d) Two letters are deleted
(x) Let G be a graph with n vertices and m edges. What is the complexity of (e) R is added to the queue (f) Two letters are deleted.
Depth First Search of G. Assume that the graph is represented using (b) Let a and b denote positive integers. Suppose a function Q is defined
adjacency matrix. recursively as follows:-
(a) O(n) (b) O(m+n) (c) O(n2) (d) O(mn). Q(a,b) = 0 if a < b
Q(a-b, b) + 1 if b <= a
Group – B Find the value of Q(2,3), Q(14,3) and Q(586,7).
6 + (1 + 2 + 3) = 12
2. (a) Algorithm RSum(a,n)
{ if (n <= 0) then 5. (a) Suppose STACK is an array of size 6 and initially STACK is empty, i.e.,
return 0; TOP = 0. A, B and ITEM are integer variables, and STACK operates on LIFO
else principle. Find the output of the following:
return RSum(a, n-1) + a[n]; Set A: = 2 and B: = 5;
} PUSH (STACK, A);
Deduce the time complexity of the above algorithm. PUSH (STACK, 4);
(b) Consider an array of 40 x 4 called Score to store the numerical grades of PUSH (STACK, B+2);
40 students in four different subjects. Suppose base address of Score is PUSH (STACK, 9);
1000 and w = 2 bytes. What will be the address of Score[25,3], i.e. the PUSH (STACK, A+B);
score of 3rd subject of 25th student in Row-Major order? What will be the Repeat while (TOP is not equal to zero)
address of the same in Column-Major order? { POP (STACK, ITEM)
PRINT : ITEM;
(c) Prove that running time T(n) = n3+ 20n+ 1 is O(n3). What do you }[ End of loop]
understand by O(1)? Return;
5 + 4 + 3 = 12
(b) Write an algorithm to convert an infix expression to its corresponding
postfix expression using stack. Using the above algorithm, convert the
3. (a) Write down (draw the nodes) the linked list expression of polynomial :
9x³ - 7x² + 9. following infix expression into postfix expression using stack. Show all the
intermediate steps with a diagram.
(b) What are the advantages of linked lists over an array. Write an algorithm A + B * C + (D / E – F) * G
to insert an element X after a given element Y, in a singly linked list. 5 + (4 + 3) = 12
Group – D
(c) Explain with diagram, how the push operation takes place in case of a
linked list implementation of Stack. Write down the algorithm for push 6. (a) Insert the following keys in the order given below to build them into an
operation in linked Stack. AVL tree 3, 2, 1, 4, 5, 6, 7, 16, 15, 14. Clearly mention different rotations
2+ (2 + 3) +(2 + 3) = 12 used and balance factor of each node.
INFO 2101 2 INFO 2101 3