PESIT Bangalore South Campus Hosur road, km before Electronic City, Bengaluru -00 Department of Information Science and Engineering Scheme For Internal Assessment Test 3 Subject & Code: Data Structures with C- 0CS35 Faculty: Mrs.R.Bharathi Note: Answer any FIVE full questions Q.No Questions a) Explain the following terms with examples: Complete Binary Tree Marks 0 A complete binary tree of depth d is the strictly binary all of whose leaves are at level d. A complete binary tree with depth d has 2d leaves and 2d- nonleaf nodes Strictly Binary Tree A full binary tree of depth k is a binary tree of depth k having 2 - nodes, k>=0. Expression tree Expression tree is a binary tree in which each internal node corresponds to operator and each leaf node corresponds to operand Binary search tree Every element has a unique key. The keys in a nonempty left subtree (right subtree) are smaller (larger) than the key in the root of subtree. The left and right subtrees are also binary search trees. Forest A forest is a set of n >= 0 disjoint trees 2 a) i) Define the following: i) Undirected Graph ii)directed Graph Undirected graph => no oriented edge. Directed graph => every edge has an orientation. [BE ISE III Semester]
b) Construct the binary tree from the given traversals: ) Preorder: A B D G C E H I F In order: D G B A H E I C F 3 a) Write a recursive C routine to implement Binary Search NODE search(node root,int key) /* return a pointer to the node that contains key. If there is no such node, return NULL */ if (root==null) return NULL; if (key == root->data) return root; if (key < root->data) return search(root->left_child, key); return search(root->right_child,key); b) Write and explain with a function, level order tree traversal void level_order(tree_pointer ptr) /* level order tree traversal */ int front = rear = 0; tree_pointer queue[max_queue_size]; if (!ptr) return; /* empty queue */ addq(front, &rear, ptr); for (;;) ptr = deleteq(&front, rear); if (ptr) printf( %d, ptr->data); if (ptr->left_child) addq(front, &rear, ptr->left_child); [Type text] [Type text] [Type text]be ISE IV Semester
PESIT Bangalore South Campus Hosur road, km before Electronic City, Bengaluru -00 Department of Information Science and Engineering if (ptr->right_child) addq(front, &rear, ptr->right_child); else break; a) Define a forest. Explain how to transform a forest into a binary tree with an example. If T, T 2,, T n is a forest of trees, then the binary tree corresponding to this forest, denoted by B(T, T 2,, T n ) () empty, if n = 0 (2) has root equal to root(t ) has left subtree equal to B(T,T 2,,T m ) has right subtree equal to B(T 2,T 3,,T n ) 5 Forest A forest is a set of n >= 0 disjoint trees A Forest A E G B E B C D F H I C F G D H I CHAPTER 5 72 [BE ISE III Semester]
b) How to represent a disjoint set? Explain Disjoint set union and find(i) operations with example. Set Representation S=0,, 7, 8, S2=,, 9, S3=2, 3, 5 0 7 8 9 S i S j = φ Two operations considered here Disjoint set union S S 2 =0,,7,8,,,9 Find(i): Find the set containing the element i. 3 S 3, 8 S 2 3 5 Array Representation for Set i [0] [] [2] [3] [] [5] [] [7] [8] [9] parent - - 2-2 0 0 0 int find(int i) for (; parent[i]>=0; i=parent[i]) return i; void union(int i, int j) parent[i]= j; CHAPTER 5 8 [Type text] [Type text] [Type text]be ISE IV Semester
PESIT Bangalore South Campus Hosur road, km before Electronic City, Bengaluru -00 Department of Information Science and Engineering 5 a) What is Winner tree? Explain with suitable example a winner tree for k=8. Complete binary tree with n external nodes and n - internal nodes. External nodes represent tournament players. Each internal node represents a match played between its two children; the winner of the match is stored at the internal node. Root has overall winner. Winner Tree for k = 8 5 5 9 8 7 7 8 0 9 9 20 8 9 90 7 2 5 20 38 2 3 8 0 20 30 5 25 28 5 50 3 95 99 8 20 run run2 run3 run run5 run run7 run8 5-5 b) Explain HBLT and WBLT with example HBLT: A binary tree is a (height biased) leftist tree iff for every internal node x, s(leftchild(x)) >= s(rightchild(x)) WBLT: Let the weight, w(x), of node x to be the number of internal nodes in the subtree with root x If x is an external node, w(x) = 0 If x is an internal node, its weight is one more than the sum of the weights of its children A binary tree is a weight-biased leftist tree (WBLT) iff at every internal node, the w value of the left child is greater than or equal to the w value of the right child a) What is priority queue? Explain various types of priority queues. [BE ISE III Semester]. Single ended priority queue It is a collection of elements in which each element has a priority Two types Max Min 2. A double-ended priority queue It is a data structure that supports the following operation:
i) Return an element with minimum priority. ii) Return an element with maximum priority. iii) Insert an element with arbitrary priority. iv) Delete an element with minimum priority. a. Delete an element with maximum priority b) What is binomial heap? Explain the steps involved in the deletion of min element from a binomial heap. A binomial heap is a data structure that supports the same functions as those supported by leftist trees. The binomial tree B k, of degree k is a tree such that if k = 0, then the tree has exactly one node, and if k > 0, then the tree consists of a root whose degree is k and whose subtrees are B 0, B,, B k-. ***************************************************** [Type text] [Type text] [Type text]be ISE IV Semester