0% found this document useful (0 votes)
349 views

CSC508

csc508

Uploaded by

aisyah
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
0% found this document useful (0 votes)
349 views

CSC508

csc508

Uploaded by

aisyah
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
You are on page 1/ 6
CONFIDENTIAL = CSIDEC 2018/CSC508/518 & UNIVERSITI TEKNOLOGI MARA FINAL EXAMINATION COURSE : DATA STRUCTURES/DATA STRUCTURE AND ALGORITHM ANALYSIS COURSE CODE : CSC508/518 EXAMINATION : DECEMBER 2018 TIME : 3HOURS INSTRUCTIONS TO CANDIDATES 1 This question paper consists of five (5) 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 jl) 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 6 printed pages © Hak Cipta Universiti Toknologi MARA CONFIDENTIAL, CONFIDENTIAL 2 CSIDEC 2018/¢SC508/518 QUESTION 4 a) List THREE (3) basic operations performed on stack. (3 marks) b) Write an application to enqueue FIVE (5) random integer values in sequences into a queue named Number. (4 marks) ¢) Figure 1 below shows a piece of coding. Write the contents for both queue and stack at both comment lines. (5 marks) public class Ql ( public static void main(String s [] ) { Stack lew Stack(); Queue y=new Queue (); for(int i= { 3; i<80; i+=13) x.push (i); } for(int j=0; 3<3; j++) { y-enqueue(x-pop()) 7 } //#e+++%%¢4comment Line 1 while (!y.istmpty ()) ( x.push(y.dequeue() ) ; ) for(int j=0; j<3; j++) { y-enqueue(x.pop() ) + y //****4*4«%Comment Line 2 } y Figure 7 (© Hak Cipta Universiti Teknologi MARA CONFIDENTIAL, CONFIDENTIAL 3 CSIDEC 2018/CSC508/518 d) Figure 2 shows the ADT of Bus and Queue classes. public class Bus { string regNo; // bus registration number String yearReg; // year registered with JPJ String owner; //name of the owner String stateReg; //which state the vehicle is registered eg. Pahang, Melaka, etc public Bus (String, String, String, String); public String getRegNo(); public String getYearReg(); public String getOwner(); public String getstate(); } public class Queue { public Queue(); public void enqueue (Object); public Object dequeue (); public Boolean isEmpty (); //definition for other methods. Figure 2 Queue named busQueue inserted with 50 busses information, write a Java program segments for the following requirements: i) Find the total number of busses which was registered in the year 2018 and display it. (Noted: In order to avoid data loss, use temporary queue to store bus information.) (4 marks) ii) From the temporary queue, move all buses that were registered in Melaka into a stack name M1kSt.ack and other busses into the original queue. (4 marks) QUESTION 2 a) Given the following list: 6, 10, 22, 29, 35, 41, 53, 76, 80, 100, 25 i) Show the values of first, last, mid and the number of comparison for search item 100. (4 marks) (© Hak Cipta Universiti Teknologi MARA CONFIDENTIAL CONFIDENTIAL 4 CSIDEC 2018/CSC508/518 ll) Show the values of first, last, mid and the number of comparison for search item 27. (4 marks) b)_ State the TWO (2) differences between sequential search and binary search. (4. marks) ©) Uist eny THREE (3) commonly used Hash Method. (3 marks) d) Given the following values to be inserted into a hash table of size 5, draw a diagram of the hash table if the function uses the modular (%) method and hashing with chaining. 43, 32, 56, 192, 1000, 26, 34 78, 16, 66 (6 marks) QUESTION 3 a) Define Heap Sort, (3 marks) b) Briefly explain the way merge sort algorithm differs from the selection sort algorithm in partitioning lists. (4 marks) ©) List out the THREE (3) operations that make up the most running time in sorting algorithm, (3 marks) 4) Given the following list, show steps to sort the list by using Merge Sort. 8, 4, 6,9, 2,3,4 (6 marke) €) Given the following list, iltustrate how Insertion sort is done. 64, 26, 93, 17, 77, 31, 44, 65, 20 (4 marks) QUESTION 4 8) Define successor and predecessor in binary tree. (3 marks) b) Briefly describe the TWO (2) types of rotation in AVL tree. (3 marks) (© Hak Cipta Universiti Teknologi MARA CONFIDENTIAL CONFIDENTIAL 5 CSIDEC 2018/CSC508/518 ©) Write an algorithm for post order traversal. (4 marks) d) Given the following lists, construct an AVL tree with the balance factor after each insertion. 322, 229, 656, 767, 888, 311, 201, 760, 995, 898 (5 marks) QUESTION 5 a) Table 1 shows the weight of edges and the adjacent nodes for nodes labeled A through F. Draw an undirected graph based on Table 1 (6 marks) Node ‘Adjacent nodes Weighis K (CO) (0, 8) B (A, C, F) (10, 7, 2) c (A,B, DE) 6.7, 12, 16) D (C,E, F) (12, 9, 5) E (C, D) (6,9) F (B,D) (2,5) Tabie 1 b) Using Kruskal's Algorithm, find the minimum spanning tree for the graph in Figure 3. (10 marks) | Figure 3 CONFIDENTIAL @ Hak Cipta Universiti Teknologi MARA CONFIDENTIAL 6 CSIDEC 2018/CSC508/518 ©) Using Djikstra Algorithm, find the shortest path from A to all other vertices for the graph in Figure 4. (10 marks) END OF QUESTION PAPER (© Hak Cipta Universiti Teknologi MARA CONFIDENTIAL,

You might also like