Code No: R21051 R10 SET - 1 II B. Tech I Semester, Supplementary Examinations, May - 2012 DATA STRUCTURES (Com. to CSE, IT, ECC ) Time: 3 hours Max Marks: 75 Answer any FIVE Questions All Questions carry Equal Marks *******-****** 1. a) Which of the given options provides the increasing order of asymptotic complexity of the n 3 / 2 functions: f 1, f 2, f3 and f 4? f1 ( n) = 2 f 2 ( n) = n f3 ( n) = nlog 2 n log 2 n f 4 ( n) = n b) i) Write a recursive C function to compute n Fibonacci numbers of the following: 1, if n = 0 f ( n) = 1, if n = 1 f ( n 1) + f ( n 2) f 7? ii) How many times f is called (including the first call) for an evaluation of ( ) 2. a) Consider an array: {25, 14, 16, 13, 10, 8, 12} represents a binary max-heap. What is the content of the array after two delete operations on a binary max-heap? b) Write a recursive quick sort algorithm. Trace the algorithm to sort the following elements: 72, 15, 22, 11, 18, 56, 40, 45 3. a) What is an equivalent infix form of the following postfix form of arithmetic expression? A B C C D E + / b) Let a circular queue is maintained in an array A[0..n-1]. What is the size of the queue in terms of F and R, where F, R indicate the FRONT and REAR indices? c) Write a C program to implement the circular queue operations using arrays. (3M+3M+9M) 4. a) Write a C program to create a doubly linked list and display all the elements in the list? b) Compare singly and doubly linked lists to perform insertion and operations. (8M+7M) 5. a) A complete n array tree is a tree in which each node has n children or no children. Let I be the number of internal nodes and L be the number of leaves in a complete n array tree. If L = 41and I = 10, then what is the value of n? b) Consider the following in-order and pre-order traversal of a binary tree. What is the postorder traversal of a binary tree? In-order Traversal: D B F E G H A C Pre-order raversal: A B D E F G H C 1 of 2
R10 SET - 1 6. a) What is a threaded binary tree? Explain with an example. b) The following numbers are inserted into an empty binary search tree in the given order one by one: 15, 32, 20, 9, 3, 25, 12, 1. i) Show the final binary search tree after the insertions. ii) Draw the binary search tree after deleting 15 from it. 7. a) Explain the graph traversal methods with suitable examples. b) How many minimum spanning trees does the following graph have? Draw all of them. 8. a) Explain the representation of sets using linked lists. b) What is an ADT? What are the ADT operations? Explain ADT implementation of a stack. 2 of 2
R10 SET - 2 II B. Tech I Semester, Supplementary Examinations, May - 2012 DATA STRUCTURES (Com. to CSE, IT, ECC ) Time: 3 hours Max Marks: 75 Answer any FIVE Questions All Questions carry Equal Marks *******-****** 1. a) Find the values of f (513, 2) and f (345, 10) for the following recursive function definition: n n mod r + f, r, if n > 0 f ( n, r) = r 0, otherwise b) Write a recursive binary search algorithm. Trace the algorithm to search the element -5 in the list of elements: -5, -3, -1, 0, 10, 15, 20, 25 2. a) What is a natural merge sort? A natural merge sort is to be used to sort the file of integers: 12, 37, 42, 9, 5, 7, 50, 40, 45, and 92. What is the order of the numbers after one pass of the sort? b) Write a selection sort algorithm. Trace the algorithm to sort the following elements: 72, 15, 22, 11, 18, 56, 40, 45 3. a) What is an equivalent infix form of the following postfix form of arithmetic expression? + A B C D / E / F + G H, where represents exponentiation b) What is the minimum number of stacks of size n required to implement a queue of size n? Explain. c) Write a C program to convert an infix expression to a postfix expression. (3M+3M+9M) 4. a) What are the lists of operations that can be performed on a singly linked list? Explain how to perform insertion and deletion operations in the middle of a singly linked list. b) What is a circularly linked list? Write a C program to display the number of elements in a circularly linked list. 1 of 2
R10 SET - 2 5. a) What is the total number of distinct binary trees with n nodes? Draw all the distinct binary trees with 5 nodes. b) Consider the following weighted binary tree: i) What is the weighted external path length of the binary tree? ii) What is the weighted degree path length of the binary tree? 6. a) A binary search tree is generated by inserting in order of the integers: 50, 15, 62, 5, 20, 58, 91, 3, 8, 37, 60, 24. What is the total number of nodes in the left sub-tree and the right sub-tree? b) What is a balanced binary tree? What is the maximum height of any balanced binary tree with 33 nodes? Assume that the height of a tree with a single node is 0. 7. a) Consider the graph, G with 12 edges. It has 6 vertices of degree 3 and the rest have degree less than 3. Determine the minimum number of vertices. b) Consider a weighted undirected graph with vertex set V = {a, b, c, d, e, f, g, h, i, j} and edge set E = {(a, b, 6), (a, c, 1), (a, d, 2), (a, e, 8), (b, d, 3), (b, g, 2), (c, d, 2), (d, h, 15), (e, f, 11), (e, h, 8), (e, i, 2), (f, h, 4), (f, i, 9), (g, h, 8), (g, i, 14), (g, j, 19), (h, i, 4), (i, j, 5)}. The third value in the tuple represents the weight of the edge specified in the tuple. What is the weight of a minimum spanning tree of the weighted undirected graph? 8. a) What is an ADT? What are the ADT operations? Explain ADT implementation of a queue. b) Explain the information storage using bit strings. (10 +5M) 2 of 2
R10 SET - 3 II B. Tech I Semester, Supplementary Examinations, May - 2012 DATA STRUCTURES (Com. to CSE, IT, ECC ) Time: 3 hours Max Marks: 75 Answer any FIVE Questions All Questions carry Equal Marks *******-****** f 5861, 7 for the following recursive function definition: 0, x < y f ( x, y) = f ( x y, y) + 1, y x b) Write a recursive C function to solve the problem oftowers of Hanoi. Trace the C function for an optimal execution time of the Towers of Hanoi problem with n = 8 discs. 1. a) Find the value of ( ) 2. a) The elements 32, 15, 20, 30, 12, 25 and 16 are inserted one by one in the given order into MaxHeap. What is the resultant MaxHeap? b) Write a recursive quick sort algorithm. Trace the algorithm to sort the following elements: 25, 7, 34, 2, 70, 9, 61, 16, 49, 19 3. a) What is an equivalent infix form of the following postfix form of arithmetic expression? A B C C D E + / b) What is a priority queue? Explain with an example. c) Write a C program to implement the queue operations using stack. (3M+3M+9M) 4. a) What is a linked list? Explain the different types of linked lists. b) What is a sparse matrix? Write C program to add two sparse matrices using linked lists. 5. a) What is the total number of distinct binary trees with 12 nodes? b) Consider the following in-order and post-order traversal of a binary tree. What is the pre-order traversal of a binary tree? In-order Traversal: B C A E D G H F I Post-order Traversal: C B E H G I F D A 6. a) The following numbers are inserted into an empty binary search tree in the given order: 10, 1, 3, 5, 15, 12, 16. What is the height of the binary search tree? b) What is a balance factor of a binary tree? Mark the balance factor of each node of the following binary tree and state whether it is height balanced or not. 1 of 2
R10 SET - 3 7. Consider a complete undirected graph with vertex set {0, 1, 2, 3, 4}. Entry Wij in the matrix W below is the weight of the edge{ i, j}. 0 1 8 1 4 1 0 12 4 9 W = 8 12 0 7 3 1 4 7 0 2 4 9 3 2 0 i) What is the minimum possible weight of a spanning tree T in this graph such that vertex 0 is a leaf node in the tree T? ii) What is the minimum possible weight of a path P from vertex 1 to vertex 2 in this graph such that P contains at most 3 edges? 8. a) Explain the representation of sets using linked lists. b) What is an ADT? What are the ADT operations? Explain ADT implementation of a stack. 2 of 2
R10 SET - 4 II B. Tech I Semester, Supplementary Examinations, May - 2012 DATA STRUCTURES (Com. to CSE, IT, ECC ) Time: 3 hours Max Marks: 75 Answer any FIVE Questions All Questions carry Equal Marks *******-****** 1. a) There are four different algorithms: A1, A2, A3, A4 to solve a given problem with the complexity n order: log n, log log 2 n, nlog 2 n, and respectively. What is the best algorithm? log 2 n Why? b) How many times f is called for an evaluation of f ( 95) in the following recursive function? n 10, if n > 100 f ( n) = f ( f ( n + 11) ), otherwise c) What is the average successful search time taken by binary search on a sorted array of 10 data items? (5M+5M+5M) 2. a) What is a randomized quick sort? Explain with an example. b) How many swapping are needed to sort the following numbers in ascending order using bubble sort? : 8, 22, 7, 9, 31, 19, 5, 13 c) If one uses straight two-way merge sort algorithm to sort the elements: 20, 47, 15, 8, 9, 4, 40, 30, 12, 17 in ascending order, and then what is the order of these elements after the second pass of the algorithm? (5M+5M+5M) 3. a) What is an equivalent infix form of the following postfix form of arithmetic expression? + A B C D / E / F + G H, where represents exponentiation b) If memory for the run time stack is only 150 cells (words), how big can n be in n! before encountering a stack overflow? c) Write a C program to implement the round-robin algorithm. Trace the program with an appropriate input data. (3M+3M+9M) 4. a) What is a circularly linked list? Write a C program to display the number of elements in a circularly linked list. b) What are the lists of operations that can be performed on a doubly linked list? Explain how to perform insertion and deletion operations in the middle of a doubly linked list. 1 of 2
R10 SET - 4 5. a) Compare trees and binary trees. b) The set: (A, (B, (E, F)), (C, (G)), (D, (H, I, J))) represents a tree. Find the number of leaf nodes in the binary tree representation of this tree. c) Consider a complete k array tree, where every internal node has exactly k children. What is the total number of leaves in such a tree with n internal nodes? (5M+5M+5M) 6. a) How many nodes will become unbalanced when a node is inserted as a child of the node G of the following balanced binary tree? b) A binary search tree is used to locate the number 43. Which of the following probe sequences are possible and which are not? Explain. 7. a) If the simple graph G has n vertices and e edges, how many edges does the G, complement of G have? If the simple graph G has 15 edges and G has 13 edges, how many vertices does G have? b) A complete, undirected, weighted graph G is given on the vertex set {0, 1, 2,..., n-1}for any fixed n. Draw the minimum spanning tree of G if: i) The weight of the edge (u, v) is u v ii) The weight of the edge (u, v) is ( i ) 61 52 14 17 40 43 ( ii ) 2 3 50 40 60 43 ( iii ) 10 65 31 48 37 43 ( iv ) 81 61 52 14 41 43 ( v ) 17 77 27 66 18 43 u + v 8. a) Explain the information storage using bit strings. b) What is an ADT? What are the ADT operations? Explain ADT implementation of a queue. 2 of 2