You are on page 1of 11
CONFIDENTIAL ss CSIMAR 2017/CSC248 UNIVERSITI TEKNOLOGI MARA FINAL EXAMINATION COURSE FUNDAMENTALS OF DATA STRUCTURES COURSE CODE : CSc248 EXAMINATION MARCH 2017 TIME 3 HOURS INSTRUCTIONS TO CANDIDATES 1 This question paper consists of two (2) parts: PART A (10 Questions) PART B (7 Questions) 2. ‘Answer ALL questions in the Answer Booklet. Start each answer on a new page. 3 Do not bring any material into the examination room unless permission is given by the invigilator. 4 Please check to make sure that this examination pack consists of i) the Question Paper ii) an Answer Booklet — provided by the Faculty 5 ‘Answer ALL questions in English. DO NOT TURN THIS PAGE UNTIL YOU ARE TOLD TO DO SO This examination paper consists of 11 printed pages © Hak Cipta Universiti Teknologi MARA CONFIDENTIAL CONFIDENTIAL 2 CSIMAR 2017/C8C248 PART A (20 MARKS) 1. Which of the following is the main purpose of implementing data structure? ‘A. to ease the programmer's tasks when writing codes for the program B. to help the user save their data C. to organise data in the computer memory during execution D. to reduce processing time during booting the computer 2. Which of the following methods of the ArrayList class is used to return the elements at a given index? A. size() B. get () C. index () D. set () 3. When user creates a reference to a link in a linked list, it must refer to the first link. must refer to the link pointed to by current node. must refer to the link pointed to by next node. can refer to any link user wants. pom> A linear list of elements in which deletion can be done from one end (front) and insertion can take place only at the other end (rear) is known as a Linked List Queue Stack Tree pop> 5. Which of the following best describes a stack? ‘A. Addition and deletion of elements ocours at any end of the sequence. Addition and deletion of elements occurs only at one end called the top. Elements are added at one end, called the rear, and deleted from the other end, called the front. Elements are added at one end, called the front, and deleted from the other end, called the rear. B. c D. (© Hak Cipta Universiti Teknologi MARA, CONFIDENTIAL CONFIDENTIAL, 3 CSIMAR 2017/CSC248 In a binary tree used to represent a arithmethic expression, which of the following is FALSE? A. To perform pre-order traversal, traverse of the left and right subtrees before processing the root element. Both children of an operator node must be operands. Following a post-order traversal, no parentheses need to be added. Following an in-order traversal, parentheses need to be added. pop 7. Abinary tree is a binary search tree if A. every non-leaf node has children whose key values are less than or equal to the parent. B. in the path from the root to every leaf node, the key of each node is greater than or equal to the key of its parent. C. every left child has a key less than the parent and every right child has a key greater than the parent. D. anode can have a maximum of two children. 8. Which of the following operations are FALSE in the algorithm for evaluating an arithmetic expression using a stack? ‘A. Operands are pushed into the stack. B. Operators are popped from the stack. C. The arithmetic equations must be in the postfix order. D. The evaluation process does not follow the operator precedence. 9. Which of the following is FALSE about data structure? A. Programmers are able to code the data structure program by using any programming languages. B. Implementing the correct data structure will reduce the computer processing time. . Processor scheduling in the computer does not apply the data structure during D. evaluating the arithmetic problems. Nature of the data and the processes that need to be performed will be the criteria concerned by the programmers to select the suitable data structure. 10. Which of the following is FALSE in describing the basic linked list concept? A B. @ D. A linked list allows direct access to their nodes. . Implementing linked list will make the computer memory become dynamic in allocating and de-allocating space. Tail will store the address of the last node in the linked list. The benefit of implementing the linked list is that the memory locations are not required to be contiguous. (© Hak Cipta Universiti Teknologi MARA, CONFIDENTIAL CONFIDENTIAL 4 CSIMAR 2017/CSC248 PART B (80 MARKS) QUESTION 1 The following is a program segment to store integer values using ArrayList ¥* Sequential List with integers values */ import java-util.ArrayList; public class Seqhist ( public static void main(String [] args) { ArrayList sample = new ArrayList (); insert ten (10)integer elements into sample ArrayList : display all elements in sample ArrayList : remove odd value in sample ArrayList a) Write a program segment at lines marked with //1: to insert 10 integer elements into sample. (3 marks) b) Write a program segment at lines marked with //2: to display all elements in sample. (2 marks) ©) Write a program segment at lines marked with //3: to remove odd element(s) from sample. (3 marks) (© Hak Cipta Universiti Teknologi MARA CONFIDENTIAL CONFIDENTIAL, 5 CSIMAR 2017/CSC248 QUESTION 2 The record department of Hospital Sultanah Fatimah is using ArrayList to keep details of the doctors. The following are the ADTs of Doctor and ArrayList. { private String docName; private char docSpecialty; // C - Cardiology N - Neurology // ~ Paediatrics G - Gynae private int docYearService; // definition of basic methods given here public class ArrayList { public ArrayList (int size) //normal constructor public boolean add (int index, Object elem); public Doctor remove (int index); public Doctor get (int index); public Doctor set (int index, Object elem); public int size(); public class Doctor | | | Assuming the record of doctors have been inserted into a sequential object named doctorlist. Write Java program segments for the following tasks: a) Delete the record of doctors from doctorList who are the specialists in neurology with less than 5 years of services. (4 marks) b) Display the details of doctor that has served the longest. (4 marks) (© Hak Cipta Universit Teknologi MARA, CONFIDENTIAL CONFIDENTIAL, 6 CSIMAR 2017/CSC248 QUESTION 3 A LinkedList is used to store Mp3 songs. The following are the ADTs of Node, LinkedList and Mp3Song classes. Public class Mp3Song ( private String singer; private String songTitle; // definition of basic methods given here ) public class Node( Mp3Song data; Node next; // definition of basic methods given here ) public class LinkedList{ private Node first; //methods define here Write a java program segment to : a) Create the method insertatFront which will add data on an Mp3 song at the front of the list. (S marks) b) Write a program segment to insert 10 records of song into a LinkedList named music. Every new record will become the head of the list. (5 marks) (© Hak Cipta Universiti Teknologi MARA, CONFIDENTIAL, CONFIDENTIAL 7 CSIMAR 2017/CSC248 QUESTION 4 A.LinkedList is used to store the score for papers submitted in a conference. The following are the ADTs of Node and LinkedList classes. public class Node{ double score; Node next; Node (double sco) { this(sco, null); } Node (double sco, Node nextNode) ( score = sco; next = nextNode; ) //definition of other methods ) public class Linkedbist( Node first, last; public boolean isEmpty() {...} public void insertScore(double score) {...} public void printScoreAccepted() {..-} //definition of other methods a) Write the definition of method insertScore (double score) to insert the given score at the end of the linked list. (3 marks) b) — Write the definition of method printScoreAccepted () to display all score marks of submitted papers in the linked list with score values 1.50 and above. (3 marks) (© Hak Cipta Universiti Teknologi MARA, CONFIDENTIAL CONFIDENTIAL 8 CSIMAR 2017/CSC248 QUESTION 5 The following is a program segment to store string values using Queue. pub: { class App public static void main(String [] args) fj | Queue firstQ = new Queue(); | Queue secondQ = new Queue(); firstQ.enqueue ("DOTS"); firstQ. enqueue ("RUNNING") ; firstQ. enqueue ("MONKEYS") ; firstQ. enqueue ("PRISON"); /P***1 store object a for (int i=0; i<4; i++) ‘ q = first.dequeue(); secondQ. enqueue (q. toString) .substring (i, i+3)); 1/***2ndQte* //*** (¢) tee while (!secondQ. isEmpty ()) { system. out .print1n(secondQ.dequeue ()) ; , a) Draw the diagram of firstg and secondo at lines marked with '***1sto***" and '***2ndo***" respectively. (3 marks) b) What is the output of the above application? (2 marks) ©) Write JAVA statements to display the total number of characters in strings stored in secondo at lines marked with "=** (c) ###! (4 marks) (© Hak Cipta Universiti Teknologi MARA CONFIDENTIAL CONFIDENTIAL, 9 QUESTION 6 a) Convert the following POSTFIX expression to INFIX expression. i) AB*C*DE-* i) PQ*RS+/UV+- b) Convert the following INFIX expression to PREFIX expression. i) AS$BI(C*D) +E i) M/N+(P*Q)$R CSIMAR 2017/CSC248 (4 marks) (4 marks) c) Given an INFIX expression, convert to POSTFIX expression then solve the expression by using stack and show all the calculation steps. ((12* 6) /(8/ 4) * (7-5) (© Hak Cipta Universiti Teknologi MARA (7 marks) CONFIDENTIAL CONFIDENTIAL, 10 CSIMAR 2017/CSC248 QUESTION 7 A survey had been done related to the health status of Segamat community. Given the HealthSurvey, TreeNode and BST ADTS: public class HealthSurvey { private int serialNo; private int age; private char gender; // M- male; F ~ female private boolean medicine; //taking medicine?if yes-true;no- false private boolean smoking;// yes - true; no - false private boolean exercise ; // yes - true ; no - false //definition of other method ) public class TreeNode { TreeNode left; //left node HealthSurvey data; //data for Survey TreeNode right; //xight node //definition of other method ) public class BST { private TreeNode root; public BST() = { ws. public int cGenderSmoking(char gen){ ... } public void displayHealthy(){ ... } The following table shows the data gathered from the survey. Serial No ‘Age Gender | Medicine | Smoking | Exercise 235 28 M ‘true true true 123 35 FE false false true 456 48 M False true false | 25 F True true false 150 50 aan False false true 123 3 F False false true a) Based on the table given, draw a Binary Search Tree (BST) according to the serial number from each respondent of the survey. (3 marks) (© Hak Cipta Universiti Teknologi MARA CONFIDENTIAL, CONFIDENTIAL, " CSIMAR 2017/CSC248 b) According to the tree drawn from a) solve the following problem i) Identify the height of the tree. ii) List the ancestor of serial number 150. ii) List the serial number of leaf node. iv) Traverse the tree in postorder traversal. v) Traverse the tree in inorder traversal (6 marks) ©) Write the definition of method cGenderSmoking (char) and its recursive method to count and return the number of respondents who smoke according to the gender given through parameter. (5 marks) 4) .Write the definition of method di splayHealthy () and its recursive method to identify and display details of respondents who exercise and do not take any medicine. (S marks) e) Inthe main program, get TEN (10) inputs to store respondents’ details into a BST object and then call for cGenderSmoking(char) and displayHealthy() (5 marks) END OF QUESTION PAPER (© Hak Cipta Universiti Teknologi MARA CONFIDENTIAL

You might also like