STUDENT IDENTIFICATION NO MULTIMEDIA COLLEGE JALAN GURNEY KIRI 54100 KUALA LUMPUR FIFTH SEMESTER FINAL EXAMINATION, 2014/2015 SESSION PSD2023 ALGORITHM & DATA STRUCTURE DSEW-E-F-2/13 25 MAY 2015 9.00 AM 11.00 AM (2 HOURS) INSTRUCTIONS TO STUDENT 1. This Question paper consists of ELEVEN (11) printed pages only. 2. This question paper consists of THREE (3) sections. Section A: Answer ALL questions. Section B: Answer ALL questions. Section C: Answer ALL questions. 3. Please write all your answers in the Answer Booklet provided.
SECTION A : OBJECTIVE QUESTIONS (20 MARKS) INSTRUCTION : ANSWER ALL QUESTIONS. 1. is a model of a data structure that specifies the type of data stored, the operations supported on them, and the types of parameters of the operations but not the implementation. A. Primitive data type B. Abstract data type C. Data structure D. Sequential list 2. The process of retrieving the top element of a stack is referred to as A. push B. pop C. peek D. empty 3. Which of the following is the characteristic of a circular linked list: A. The null pointer at the end of the list replaced with a pointer to the beginning of the list B. Its nodes has two links to the next and previous nodes C. It has an empty header node D. It allows data about circles and links to be stored 4. Which of the following is TRUE about queues? i. A queue is referred to as a LIFO data structure ii. It is a type of list iii. The method to removed data from a queue known as dequeue A. i, ii and iii B. i and iii C. ii and iii D. ii only SFCS Page 2 of 11
5. Which of the following features is related to encapsulation? A. Classes contain both data members and member functions. B. Abstract base class contains pure virtual functions. C. is-a relationship of classes. D. Class template describes a class in terms of a data-type parameter. 6. In a binary search tree, which traversal algorithm will cause the data in the tree to be processed in sorted order? A. inorder B. preorder C. postorder D. None of the above 7. Two main measures for the efficiency of an algorithm are: A. Processor and memory B. Complexity and capacity C. Time and space D. Data and space 8. Finding the location of the element with a given value is: A. Traversal B. Search C. Sort D. None of the above 9. The operation of processing each element in the list is known as. A. sorting B. merging C. inserting D. traversal SFCS Page 3 of 11
10. Which of the following statements about binary trees is NOT true? A. Every binary tree has at least one node. B. Every non-empty tree has exactly one root node. C. Every node has at most two children. D. Every non-root node has exactly one parent. 11. The insertion of an element into a stack must do from where? A. On the top of the stack. B. In the middle of the stack. C. On the bottom of the stack. D. In any empty spot of a stack. 12. Stack is also called as. A. Last in First out B. First in Last out C. Last in Last out D. First in First out 13. is the term used to delete an element from the stack. A. Push B. Pull C. Pop D. Pump 14. Which of the following accurately illustrates Linked List? A. The last node is linked to the header B. Implementation of a Linked List is FIFO C. The list is linked to another list D. The data are stored in a collection of nodes. Each node contains data and a link to the next node. SFCS Page 4 of 11
15. Which of the following are linear types of data structure? i. Linked list ii. Stack iii. Binary Tree iv. Queue A. i, iii and iv only B. ii, iii and iv only C. i, ii and iv only D. i, ii, iii and iv 16. The pointer to the beginning of the list is known as. A. ADT B. pointer C. head pointer D. node 17. Deletion operation is done using in a queue. A. front B. rear C. top D. list 18. There are five items: 1, 2, 3, 4, and 5 are pushed into a stack, one after another starting from 1. The stack is popped out four times and each element is inserted in a queue. Then, two elements are deleted from the queue and pushed back into the stack. Now one item is popped from the stack. The popped item is? A. 5 B. 2 C. 3 D. 4 SFCS Page 5 of 11
19. The postfix form of A*B+C/D is A. *AB/CD+ B. AB*CD/+ C. A*BC+/D D. ABCD+/* 20. Which of the following are the sequences of steps for a postorder traversal of a tree? i. Process the value in the node. ii. Traverse the left subtree postorder. iii. Traverse the right subtree postorder. A. i, ii, iii B. ii,i, iii C. iii, i, ii D. ii, iii, i SFCS Page 6 of 11
SECTION B : TRUE (T) OR FALSE (B) (20 MARKS) INSTRUCTION : ANSWER ALL QUESTIONS. 1. Graph is a linear data structure. 2. The data structure used by recursion is stack. 3. Queue works on the strategy First in First out. 4. The name of a constructor is the same as the name of the class. 5. A constructor without parameters is called the normal constructor. 6. The public members of a class are not accessible outside the class. 7. By default, all members of a class are private. 8. Pointer variables contain the addresses of other variables as their values. 9. A single linked list can be traversed in either direction. 10. In a linked list, nodes can be inserted either at the beginning, middle or the end of list. 11. By using a data structure, programmers can hide implementation details of program codes from the user. 12. Flowchart is an English-like representation of the code required for an algorithm. 13. With an ADT, users are not concerned with what the task is done; rather, they need to be concerned only with how it can do. 14. The last element in the queue is called null. SFCS Page 7 of 11
15. Middle element in a queue can be accessed. 16. In postfix notations, the operator comes after the operands. 17. A linked list is a linear collection of self-referential structures, called nodes, connected by pointer links hence, the term "linked" list. 18. Arrays are dynamic, so the length of an array can increase or decrease as necessary. An array is appropriate when the number of data elements to be represented in the data structure is unpredictable. 19. Queue nodes are removed only from the front (head) of a queue and are inserted only at the back (tail) of the queue. 20. A node with no children is called a leaf node. SFCS Page 8 of 11
SECTION C : SUBJECTIVE QUESTIONS (60 MARKS) INSTRUCTION : ANSWER ALL QUESTIONS. Question 1 a) What is an algorithm? List THREE (3) characteristics of an algorithm? b) Give TWO (2) techniques that can be used to write an algorithm. (8 Marks) (2 Marks) Question 2 Given the nodes in liked list containing the integer values 16, 27, 92. Draw a picture of each type of the following linked list using the integer values given. (Do not use any dummy nodes) a) singly linked list b) circular linked list c) doubly linked list (9 Marks) Question 3 a) Convert the expression (A + B) * C - (D - E) * (F + G) to equivalent Prefix and Postfix notations. (6 Marks) b) Show the sequence of stack configuration in the evaluation of the following postfix expression = 2 4 * 9 5 + (5 Marks) SFCS Page 9 of 11
Question 4 Based on the binary tree given below, answer the following questions: a) What is the root element? b) How many elements are in the tree? c) How many leaves (leaf) are in the tree? d) What is the depth of the tree? e) What is the height of the tree? f) What would the output be if the elements were written out during: i. Preorder Traversal ii. Inorder Traversal iii. Postorder Traversal (5 Marks) (5 Marks) (5 Marks) SFCS Page 10 of 11
Question 5 Based on the following declarations: class Books { private: char title[50]; long ISBN; char publisher[50]; int year; float cost; public: Books(); Books(char[],long,char[],int,float); void ReadBookRecord(); void DisplayBookRecord(); ~Books(); }; a) How many members does class Books have? b) How many private members does class Books have? c) How many constructors does class Books have? List type of constructor use in class Books. (3 Marks) d) Write the definition of the default constructor of the class Books so that the private member variables are initialized to 0. (5 Marks) End of Page. SFCS Page 11 of 11