FINAL EXAMINATION COURSE COURSE CODE EXAMINATION TIME DATA STRUCTURES / DATA STRUCTURE AND ALGORITHM ANALYSIS CSC508/518 APRIL 2010 3 HOURS INSTRUCTIONS TO CANDIDATES 1. This question paper consists of six (6) questions. Answer ALL questions in the Answer Booklet. Start each answer on a new page. 2. 3. Do not bring any material into the examination room unless permission is given by the invigilator. Please check to make sure that this examination pack consists of: i) the Question Paper ii) an Answer Booklet - provided by the Faculty DO NOT TURN THIS PAGE UNTIL YOU ARE TOLD TO DO SO This examination paper consists of 7 printed pages Hak Cipta Universiti Teknologi MARA CONFI DENTI AL CONFIDENTIAL 2 CS/APR 2010/CSC508/518 Answer ALL questions QUESTION 1 a) Verify whether the following statements are TRUE or FALSE. i) The head of the linked list serves as the top of the stack when implementing stack using linked list. ii) A circular linked list has nodes with two references; one to the next node and one to the previous node. iii) A graph is called a simple graph if it has loops and parallel edges. iv) In open hashing, the data is organized in linked lists and the hash table is an array of references to the linked lists. v) The level of the children of the root node is 0. (5 marks) b) Fill in the blanks with the correct word. i) Using the process of insertion and deletion are dynamic. ii) is a way of writing arithmetic operations that places the operator in front of the two operands. iii) A is a data structure where an item can be inserted only at one end and removed at the other end. iv) An undirected graph is called if there is a path from any vertex to any other vertex. v) In a , every leaf has the same depth, and every nonleaf has two children. (5 marks) Hak Cipta Universiti Teknologi MARA CONFIDENTIAL CONFIDENTIAL 3 CS/APR 2010/CSC508/518 QUESTION 2 Given the following CreditCard, LinkedList and Queue ADTs: public class CreditCard { private String custName; private String cardNo; private String cardType; private double balance; // customer's name II card number // classic or gold card // outstanding balance public CreditCard (String, String, String, double) {...} public String getName () {...} public String getNo (){...} public String getType () {...} public double getBalance () {...} } public class Node { Object data,- Node next; } public { class LinkedList Node head,tail,newNode; public LinkedList () {...} public void insertAtBack(Object) public Object getFirst () {...} public Object getNext () {...} {...} //insert element // return the first element // return the next element public class Queue { publ i c Queue () {...} publ i c void enqueue (Object elem) {...} / / i ns er t element publ i c Object dequeue () {...} / / remove element publ i c boolean isEmpty () {...} / / check i f t he queue i s empty a) Write the complete definition for the method i nser t At BackO in the Li nkedLi st class above to insert a node at the back of the linked list. (4 marks) Hak Cipta Universiti Teknotogi MARA CONFIDENTIAL CONFIDENTIAL 4 CS/APR 2010/CSC508/518 b) Write Java statements to perform the following operations: i) Declare a linked list named c ar dLi s t and TWO (2) queues named classicQueue and goldQueue. (2 marks) ii) Insert Cr edi t Car d objects into the linked list named c ar dLi s t as many as the user wants. (3 marks) iii) From the linked list named c ar dLi s t , separate the classic card and gold card objects and store them in the queue named cl assi cQueue and goldQueue respectively. (4 marks) iv) Display the details of classic card holders with outstanding balance more than RM10,000. (4 marks) QUESTION 3 a) Among all the sorting algorithms, which algorithm is particularly efficient for an array that is already sorted? Which is particularly less efficient? Explain your answers. (3 marks) b) Given the following array of integers: 89 76 74 37 32 39 66 20 26 Show the new array after each pass of the following: i) Insertion sort ii) Selection sort iii) Heap Sort iv) Quick Sort (4 marks) (4 marks) (4 marks) (4 marks) > Hak Cipta Universiti Teknologi MARA CONFIDENTIAL CONFIDENTIAL 5 CS/APR 2010/CSC508/518 QUESTION 4 a) List TWO (2) advantages of open hashing. (2 marks) b) Suppose that the size of the hash table is 1001 and the table has 850 items. What is the load factor? (2 marks) c) Given the following input data: 1971, 1233, 6173, 5199, 4343, 7679, 1992, 2019, 3245, 4236 And a hash function h( x) = x (mod 1 0), draw the 10-item hash table resulting from hashing the keys above and handle collisions using: i) chaining. (5 marks) ii) linear probing. (5 marks) QUESTION 5 a) Given the following arithmetic expression: + * A B - * $ C D / E F G i) Convert the expression above into infix and postfix notation. (6 marks) ii) Draw the expression tree for the above arithmetic expression. (3 marks) iii) Evaluate and draw the sequence of stack configurations for the postfix expression in i) if all operands are equal to 3. (5 marks) Hak Cipta Universiti Teknologi MARA CONFIDENTIAL CONFIDENTIAL 6 CS/APR 2010/CSC508/518 b) State the values visited if these traversal methods are used for the binary tree below: i) inorder traversal (2 marks) ii) preorder traversal (2 marks) iii) postorder traversal (2 marks) QUESTION 6 Let G be a graph whose vertices are the integers 0 through 7, and let the adjacent vertices of each vertex and weights of its edges be given by the table below: Vertex 0 . 1 2 3 4 5 6 7 Adjacent Vertices ( 1 , 3) (0, 2, 3, 4) (1 ,4) (0, 1 , 5, 6) (1 , 2, 6, 7) (3,6) (3, 4, 5, 7) (4,6) Weights (1 0,5) (10, 15,20,10) (15,5) (5,20,1 0,1 5) (1 0,5,25, 15) (10,5) (1 5,25,5,20) (15,20) Note: Edge (0,1) has weight of 10 and edge (0,3) has weight of 5 a) Draw graph G. b) Draw the adjacency matrices. Hak Cipta Universiti Teknologi MARA (4 marks) (2 marks) CONFIDENTIAL CONFIDENTIAL 7 CS/APR 2010/CSC508/518 c) Draw the adjacency lists. (2 marks) d) Give the sequence of vertices of G visited using a Depth-First Search traversal starting at vertex 0. (3 marks) e) Give the sequence of vertices of G visited using a Breadth-First Search traversal starting at vertex 0. (3 marks) f) Find the minimum spanning tree that includes all vertices and calculate the total weight using Prim's algorithm (Show the step-by-step process). (6 marks) END OF QUESTION PAPER Hak Cipta Universiti Teknologi MARA CONFIDENTIAL
K.T. Chau, R.H.C. Wong, T.-f. Wong (Auth.), STAVROS K. KOURKOULIS (Eds.) - Fracture and Failure of Natural Building Stones_ Applications in the Restoration of Ancient Monuments-Springer Netherlands (2