First Question Q1 B1 Choose the best Answer: No. of Branches (1) (10/50) 1) 2) 3) 4) Suppose we start with an empty stack and then perform the following operations: Push (A); Push (B); Pop; Push (C); Top; Pop; what will be the contents of the stack after these operations? a) B,A,C b) B,C,A c) A d) A,B,C e) None of the above You have implemented the queue with a linked list, keeping track of a front node and a rear node with two reference variables. Which of these reference variables will change during an insertion into an EMPTY queue? a) Neither changes b) Only front changes c) Only rear changes. d) Both change. Suppose that we are working with linked lists that are circular, singly-linked, and have no head node. Suppose that the link field is named next. Assume L is the first node in a nonempty list, and let x be any node in this list. Which of the statements below is true if and only if x is the last node in the list? a) x = null b) x.next = null c) x.next = L d) x.next = L.next Suppose that a certain binary tree on seven nodes has in-order traversal PQRSTUV and postorder traversal QRPTUVS. What is the last character in its preorder traversal? a) R b) S c) T d) U e) V 1/8
5) Consider the following pseudocode: declare a stack of characters while ( there are more characters in the word to read ) { read a character push the character on the stack } while ( the stack is not empty ) { pop a character off the stack write the character to the screen } What is written to the screen for the input "carpets"? a) Serc b) carpets c) Steprac d) ccaarrppeettss. 6) What letter is in the fourth node in an inorder traversal of the tree below? A b) B. c) C. d) D. e) E. 7) Which of the choices below is Not a complete binary tree? Circle the choice. 8) Suppose you push 10, 20, 30, and 40 onto the stack. Then you pop three Items. Which one is left on the stack? a) 40 b) 10 c) 20 d)30 2/8
9) When the array stack is empty the top t is equal to : a) 0 b) 1 c) -1 d) NULL 10) Suppose you insert 15, 25, 35, and 45 into a queue. Then you remove three items. Which one is left? a) 45 b) 35 c) 15 d) 25 Second Question No. of Branches (3) Q2 B1 Given the following Binary Tree, Solve the following Questions? (20/50) (7/20) Q2 B2 a) What are the ancestors of node E? --------------------- b) What are the descendants of node B? --------------------- c) What is the height of the tree? --------------------------- d) What is the maximum possible number of nodes at the level of node G? ------------- e) What is the result of visiting this tree using inorder traversal? ----------------------------------------------------------------------------------- f) What is the result of visiting this tree using preorder traversal? ----------------------------------------------------------------------------------- g) What is the result of visiting this tree using postorder traversal? -----------------------------------------------------------------------------------. 3/8 (5/20)
Consider the following fully parenthesized arithmetic expression: (1 - (((3+4) * (5-6)) / (7*9))) Draw an expression tree for this expression Q2 B3 (8/20) Write the Algorithm of the Inorder Traversal of a Binary Tree? 4/8
Third Question No. of Branches (3) (20/50) Q3 B1) Write a program that reads in a sequence of characters and prints them in reverse order. Use a stack. (5/20 )............ 5/8
Q3 B2 ) (5/20 ) Suppose we are dealing with linked lists that are doubly-linked, have no list header, and are not circular; let L be the first node in the list. The Node class has three fields: data, next, and prev, with the usual meanings. Below is an example of this representation for the list A,B,C,D,E. Write a JAVA Method deletesecond(l) that deletes the second node in the list that L represents. 6/8
Q3 B3 ) (5/20) A palindrome is a word that reads the same forward as it does backward. For example, the following words are palindrome, because we can read these words backward the same way as if we read them forward:radar, hannah, refer, stats, level Write a method called CheckPal that takes the word as an array of characters, this method uses stack to checks if the given word is palindrome or not. 7/8
Q3 B4 ) (5/20) Write a complete java program that has a class called recursion which includes a recursive method called sum_range which takes two integers n, m and then returns the sum of integers from n to m. Call the method in the main and then print the result End of Questions Good Luck 8/8