Data Structures and Algorithms Mid-Semester Test: BITS Pilani-K K Birla Goa Campus
Data Structures and Algorithms Mid-Semester Test: BITS Pilani-K K Birla Goa Campus
Mid-Semester Test
BITS Pilani- K K Birla Goa Campus
Total: 60 Marks Time : 90 Minutes
Weightage: 30% March 06, 2018
Course No: CS F211
Note:
1. All parts of a question should be answered consecutively. Each answer should start from a fresh page.
2. Assumptions made if any, should be stated clearly at the beginning of your answer.
2. (a) Write a pseudocode to rearrange elements of a given array such that all those
originally stored at odd indices should be placed before those at even in-
dices. For example, if the input array is 1,2,3,4,5,6,7,8 then the output array is
1,3,5,7,2,4,6,8. (5 Marks)
In a doubly linked list each node has two pointers (except head and tail), one
to its successor and one to its predecessor.
(b) Write a pseudocode for inserting a key k after a node u on a doubly linked
list. (2 Marks)
(c) Write a pseudocode for deleting a node u on a doubly linked list. (2 Marks)
3. (a) Write a pseudocode for all queue operations (enqueue, dequeue, size, isEmpty,
front) when queues are implemented using circular arrays. (5 Marks)
(b) Write a pseudocode for pop if stack is implemented using two queues. What
is the time complexity? (4 Marks)
4. (a) A certain Professor Amongus claims that if a binary tree which stores ele-
ments in its internal nodes has the following property, then it is a binary
search tree. For every node v, the element stored at the left child of v is less
than or equal to the element stored at v and the element stored in the right
child of v is greater than or equal to the element stored at v. Is the Professor
making a correct claim? (3 Marks)
(b) Provide an example of a proper binary tree with n nodes and size of its array
based representation is Ω(n). (3 Marks)
(c) Construct an AVL tree T by inserting the keys (in the given order) into an
empty tree: (15,16,22,45,2,10,28,30,50,12,1). (4 Marks)
(d) For the above AVL tree, illustrate the delete operation by deleting the root
node. (3 Marks)
(e) Prove that height of the AVL tree is O(log n). (4 Marks)
5. (a) Illustrate heap sort for the input (5, 16, 22, 45, 2, 10, 18). (4 Marks)
(b) Suppose the binary tree T used to implement a heap can be accessed using
only the methods of the binary tree ADT. That is, we cannot assume T is im-
plemented using an array. Given a reference to the current last node, v, de-
scribe an efficient algorithm for finding the insertion point (that is, the new
last node) using just the methods of the binary tree interface. Be sure and
handle all possible cases. What is the running time of this method? (7 Marks)
Page 2