# CS 302 – DATA STRUCTURE & ALGORITHMS

Multiple Choice Type Questions
1. i) Maximum possible height of an AVL Tree with 7 nodes is a) 3 c) 5 b) 4 d) 6 ii) Worst case time complexity of the heap sort algorithm is a) O( Nlog2 N) b) O( Nln N) iii) The prefix notation is also known as a) Polish notation b) reverse Polish notation c) O( n )
2

iv) Which of the following statements are true in case of Depth-First-Traversal? i) DFS is used to determine statements are true in case of Depth-First-Traversal? ii) DFS is used to determine acyclic nature of a graph a) only (i) is true b) only (ii) is true b) both (i) and (ii) are true d) all are false v) Structure in C is an

c) both (a) and (b) d) none of these vi) What is suitable efficient data structure to construct a tree? a) b) c) d) Linked list Stack Queue none of these

m

a) user defined data type

yw

bu

t.c

c) reverse Polish notation d) none of these

om

d) O( n )

3

vii) A graph G with n nodes bipartite if it contains a) n edges b) a cycle of odd length c) no cycle of odd length d) n edges viii) The ratio of items present in the hash table, to the total table size is called a) balanced factor b) load factor ix) Adjacency matrix of a digraph is a) O ( n ) b) O ( log2 n ) c) O ( 2 )
n 2

c) item factor d) none of these

a) M + (i – j) * m + j – 1 b) M + i * m + j

yw

xi) In which collision processing method, it is not required to detect a given list position, if it is occupied or not? c) Rehashing d) None of these

xii) The height difference of any node in an AVL tree is a) -1, 0, 1 b) -2, 0, 1 c) -2, 0, 2 d) -1, 0, 2

2. Convert the following into postfix: a+bхc\$d–(e–fхg)/h 3. Write an algorithm for inorder traversal of a threaded binary tree. 4. Is circular queue a non-linear data structure? Justify your answer. 5. What is Hashing? What is Linear Probing? 6. Write an algorithm to delete a node from a doubly linked list, where a node contains one data and two address (prev & next) portion.

m

bu

t.c

x) A is an array of size m * n, stored in the row major order. If the address of the first element in the array is M, the address of the element A (i, j) (A (0, 0) ) is the first element of the array and each element occupies one location in memory that is c) M + (j – 1) * m + i -1 d) M + (i -1) * n + j -1

om
d) O ( nlog2 n )

7. Create a AVL tree by inserting the following numbers in the order in which they are given: 17 25 19 23 75 Draw figure for each step. 8. Distinguish between linear and non-linear data structure with suitable example.

9. a) Represent the following polynomial by linked list (show the diagram only) : 9x + 3x – 8x + 15 b) Convert the following: i) A + ( ( ( B – C ) * ( D – E ) + F ) / G ) \$ ( H – I ) [POSTFIX] ii) ABC - / DEF + * + [PREFIX] c) Write an algorithm to add two polynomials. 10. a) What is a graph? Find out the shortest path between all pairs of nodes in the given graph by Kruskal’s algorithm.
5 3

11. a) In a 2-tree, if E be the external path length, P be the internal path length and Q be the number of vertices that are not leaves, then prove that E = P + 2Q b) Write a function to delete any node from a binary search tree. c) The in-order & pre-order traversal sequence of nodes in a binary tree are given below: In-order: Pre-order: E F A A C E K K F C H D D H B G G B

m

b) Write down the DFS algorithm. c) Define a directed graph. Provide an example.

yw

bu

t.c

om

12. a) Construct the following Queue of characters where Queue is a circular array which is allocated six memory cells. FRONT = 2 REAR = 4 QUEUE: _ , A, C, D, _, _ Describe the Queue as the following operations take place: i) F is added to the Queue ii) Two letters are from the Queue iii) K, L, M are added to the Queue iv) Two letters are deleted from the Queue v) R is added to the Queue vi) One letter is deleted from the Queue b) What is tail recursion? How is it different from ordinary recursion? What are the difference between iteration and recursion?

m

yw

bu

13. a) Why is hashing referred as a heuristic search method? b) Write an algorithm for heap sort algorithm. c) Define a B-Tree. Insert the following keys into a B-Tree of order 3. (i.e. the B-tree is a 3-way tree) A F B K H M E S R C L N U P

t.c

om

c) Write the push( ) and pop( ) functions for a stack after describing the Data-Structure clearly.