You are on page 1of 2

DATA STRUCTURES AND ALGORITHM

Final Paper

Total Marks = 50 Time Allowed = 3 Hours

Question 1: (10 marks)

a) The inorder and preorder traversal of a tree are given below:

i. Inorder: DBMINEAFCJGK
ii. Preorder: ABDEIMNCFGJK
Construct the corresponding binary tree.

b) Determine the postorder traversal of the tree drawn.


c) Write a program to insert a new element in the given unsorted array at kth position.

• Check if the heap property is


satisfied (How do you write a code to
check this?)
23, 10, 9, 2, 10, 8, 4, 11, 7, 5, 6, 3, 2,
1, 0, 9
Question 2: (10 marks)

a) Differentiate between array and a stack.


b) Consider a two-dimensional array A of order [25*4]. The base address of the array
is 400, words per memory cell is 4. Find the address of cell A [12,4] using row major
and column major addressing.

Question 3: (20 marks)

a) Take an initially empty hash table with five slots, with hash function h(x) = x mod 5,
and with collisions resolved by chaining. Draw a sketch of what happens when
inserting the following sequence of keys into it: 35, 2,18, 6, 3, 10, 8, 5. [You are not
requested to draw the intermediate stages as separate figures, nor to show all the
fields of each entry in detail.]
b) Repeat part (a) but with the following three changes: the hash table now has ten
slots, the hash function is h(x) = x mod 10, and collisions are resolved by linear
probing.
c) Imagine a hash table implementation where collisions are resolved by chaining but
all the data stays within the slots of the original table. All entries not containing
key–value pairs are marked with a Boolean flag and linked together into a free list.
(i) Give clear explanations on how to implement the set (key, value) method in
expected constant time, highlighting notable points and using high-level pseudocode
where appropriate. Make use of doubly-linked lists if necessary.
(ii) Assume the hash table has 5 slots, is initially empty and uses the hash function
h(x) = x mod 5. Draw five diagrams of the hash table k representing the initially
empty state and then the table after the insertion of each of the following key–value
pairs: (2, A), (2, C), (12, T), (5, Z). In the final diagram, draw all the fields and
pointers of all the entries.

Question 4: (10 marks)

a) Write a program to implement a linear linked list, showing all the operations that
can be performed on a linked list.
b) Differentiate between a singly linked list and doubly linked list.
c) Write an algorithm for insertion in a sorted linked list.

You might also like