




























Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Assignment 2 - Data Structure & Algorithms - PASS
Typology: Assignments
Limited-time offer
Uploaded on 12/26/2022
4.7
(58)39 documents
1 / 36
This page cannot be seen from the preview
Don't miss anything!





























On special offer
DATA STRUCTURE & ALGORITHMS
ASSIGNMENT 2 FRONT SHEET Qualification BTEC Level 5 HND Diploma in Computing Unit number and title Unit 19: Data Structures and Algorithms Submission date 25/12/2022 Date Received 1st submission Re-submission Date Date Received 2nd submission Student Name Huynh Minh Huy Student ID GCD Class GCD1001 Assessor name Ho Van Phi Student declaration I certify that the assignment submission is entirely my own work and I fully understand the consequences of plagiarism. I understand that making a false declaration is a form of malpractice. Student’s signature (^) Huy Grading grid P 4 P 5 P 6 P 7 M 4 M 5 D3 D
ACKNOWLEDGEMENT First of all, I would like to thank the curators of the University of Greenwich, who make these courses available to students. I would like to thank all the authors and researchers who have researched about this data. In addition, I would like thank speaker Ho Van Phi for his very good and professional lectures and tutorials. Finally, I would like to thank the teachers and responsible staff of our university for providing a good learning environment.
Table of Contents INSTRODUCTION .................................................................................................................................................... 6 CHAPTER 1: IMPLEMENT COMPLEX DATA STRUCTURES AND ALGORITHMS. ................................. 7 I. Implement a complex ADT and algorithm in an executable programming language to solve a well defined problem. (P4).............................................................................................................................................. 7
INSTRODUCTION Data Structures are the programmatic method of storing data in order for it to be used efficiently. Almost every corporate program makes use of numerous sorts of data structures in some fashion. This lesson will provide you with a solid grasp of Data Structures, which is required to comprehend the complexity of enterprise level programs and the requirement for algorithms and data structures. An algorithm is a step-by-step technique that outlines a collection of instructions that must be followed in a certain order to get the intended result. Algorithms are often developed independently of underlying languages, which means that an algorithm may be implemented in more than one programming language. Following the presentation of ADT from the previous report assignment 1. In this report assignment 2, I utilized ADT such as Queue or Stack to create a Send Message program with certain requirements, and I analyzed the program's performance.
CHAPTER 1: IMPLEMENT COMPLEX DATA STRUCTURES AND ALGORITHMS. I. Implement a complex ADT and algorithm in an executable programming language to solve a well defined problem. (P4)
Class Messenger: public class Messenger { int bufferLimit = 150 ; int messageLimit = 250 ; String S2= ""; Runtime rt = Runtime. getRuntime (); // long beforeUsedMem=Runtime.getRuntime().totalMemory()- Runtime.getRuntime().freeMemory(); // long afterUsedMem=Runtime.getRuntime().totalMemory()- Runtime.getRuntime().freeMemory(); // long actualMemUsed=afterUsedMem-beforeUsedMem; long beforeUsedMem; long afterUsedMem; public Messenger() { } public void sendingMessage(String messageSource ){ rt.gc(); beforeUsedMem = rt.totalMemory() - rt.freeMemory(); Queue myQueue = new Queue(bufferLimit); char[] S1 = messageSource .toCharArray(); int n = 0 ; try { while(n < S1.length && n < messageLimit) { while(myQueue.count() < bufferLimit && n < messageLimit) { myQueue.enQueue(S1[n]); n++; if (myQueue.isFull()){ afterUsedMem = (rt.totalMemory()-rt.freeMemory()); } } // Measure if (afterUsedMem == 0 ){ afterUsedMem = (rt.totalMemory()-rt.freeMemory()); } // When buffer full push
while(myQueue.count()!= 0 ){ S2 = S2 + myQueue.deQueue(); } } } catch (Exception e ){ while(myQueue.count() != 0 ){ S2 = S2 + myQueue.deQueue(); } } } public void printMessage(){ System.out.println("(S2) This is your message:"); System.out.println(S2); System.out.println(); } // public void printMemoryUsage(){ // System.out.println("Amount of used memory: " + used_mem); // } } Figure 2 : Class Messenger. Class TimeExcution: public class TimeExecution { double start; double stop; public TimeExecution(){ start = stop = 1 ; } public double Elapse(){ return stop - start; } public void Start(){ start = System. currentTimeMillis (); }
// Show message messenger.printMessage(); // Show successfully sent message System.out.println("Successfully Sent " + messenger.S2.length() + " Characters!"); System.out.println(); // Show buffer size System.out.println("Buffer Size: " + messenger.bufferLimit); System.out.println(); // Show time execution System.out.println("Executed time: " + timeExecution.Elapse() + " millisecond"); System.out.println(); // Show memory System.out.println("Memory Usage before send message: " + (messenger.beforeUsedMem) / 1024 + " KB"); System.out.println(); System.out.println("Memory Usage after send message: " + messenger.afterUsedMem / 1024 + " KB"); System.out.println(); System.out.println("Memory used: " + (messenger.afterUsedMem- messenger.beforeUsedMem)/ 1024 + " KB"); System.out.println(); } else { // Show error System.out.println("Your input too long, up to " + sourceMessage.length()
// Send message messenger.sendingMessage(sourceMessage); timeExecution.Stop(); // Show message messenger.printMessage(); // Show successfully sent message System.out.println("Successfully Sent " + messenger.S2.length() + " Characters!"); System.out.println(); // Show buffer size System.out.println("Buffer Size: " + messenger.bufferLimit); System.out.println(); // Show time execution System.out.println("Executed time: " + timeExecution.Elapse() + " millisecond"); System.out.println(); // Show memory System.out.println("Memory Usage before send message: " + (messenger.beforeUsedMem) / 1024 + " KB"); System.out.println(); System.out.println("Memory Usage after send message: " + messenger.afterUsedMem / 1024 + " KB"); System.out.println(); System.out.println("Memory used: " + (messenger.afterUsedMem- messenger.beforeUsedMem)/ 1024 + " KB"); System.out.println(); } //Show memory // System.out.println("Memory Usage before send message: " + messenger.); // System.out.println(); // System.out.println("Memory Usage after send message: " + messenger.afterUsedMem); // System.out.println(); // messenger.printMemoryUsage();
II. Implement error handling and report test results. (P5)
try { while(n < S1.length && n < messageLimit) { while(myQueue.count() < bufferLimit && n < messageLimit) { myQueue.enQueue(S1[n]); n++; if (myQueue.isFull()) { afterUsedMem = (rt.totalMemory()-rt.freeMemory()); } } // Measure if (afterUsedMem == 0 ) { afterUsedMem = (rt.totalMemory()-rt.freeMemory()); } // When buffer full push while(myQueue.count()!= 0 ) { S2 = S2 + myQueue.deQueue(); } } } catch (Exception e ){ while(myQueue.count() != 0 ){ S2 = S2 + myQueue.deQueue(); } } Figure 7 : Try-Catch Implementation. After using “Try – Catch” we could know where is bug in our program then fixed it to make the system work well.
Test No Function being tested Testing method Test Data Expected result 1 Test the system if input a NULL string message. Input nothing in the input phase and press Enter NULL Console display: “Your input is empty, please input again to send message!” 2 Test the system if input a string over 250 characters. ( characters) Input data in input phase and press Enter “You must produce at least 250 words for IELTS Writing Task 2. You will be given a topic to reply to, and your ability to do so will be evaluated. This will involve expressing and defending an opinion, addressing the subject, summarizing specifics, outlining issues, suggesting potential solutions, and supporting your writing with arguments.” Console display: “Your input too long, up to 341 characters, some part of message might not get send, because we only send messages with a maximum of 250 characters. (S2) This is your message: You must produce at least 250 words for IELTS Writing Task 2. You will be given a topic to reply to, and your ability to do so will be evaluated. This will involve expressing and defending an opinion, addressing the subject, summarizing specifics, ou Successfully Sent 250 Characters! Buffer Size: 150 Executed time: 18.0 millisecond Memory Usage before send message: 1857 KB Memory Usage after send message: 2103 KB Memory used: 245 KB ----< Thank you for using GreMes >---- ----< Press any key to exit >----“ 3 Test the system if input a string in range 0 – 250 characters. ( characters) Input data in input phase and press Enter “The Cup of Coffee has established itself as the local coffee business with the quickest growth. If you've already seen one on your neighborhood corner, look across the street to see another.” Console display: “The Cup of Coffee has established itself as the local coffee business with the quickest growth. If you've already seen one on your neighborhood corner, look across the street to see another. (S2) This is your message: The Cup of Coffee has established itself as the local coffee business with the quickest growth. If you've already seen one on your neighborhood corner, look across the street to see another. Successfully Sent 190 Characters!
Buffer Size: 150 Executed time: 22.0 millisecond Memory Usage before send message: 1845 KB Memory Usage after send message: 2090 KB Memory used: 245 KB ----< Thank you for using GreMes >---- ----< Press any key to exit >----“ 4 Test program when input message that have special characters Input data in input phase and press Enter “Data Structure & Algorithms is important” Console display: “Data Structure & Algorithms is important. (S2) This is your message: Data structure & algorithms are crucial. Successfully Sent 40 Characters! Buffer Size: 150 Executed time: 18.0 millisecond Memory Usage before send message: 1845 KB Memory Usage after send message: 0 KB Memory used: - 1845 KB ----< Thank you for using GreMes >---- ----< Press any key to exit >----“ 5 Test time and space methods Input data in input phase and press Enter “The Highlands Coffee has established itself as the local coffee business with the quickest growth. If you've already seen one on your neighborhood corner, look across the street to see another.” Console display: “Executed time: 20.0 millisecond Memory Usage before send message: 1845 KB Memory Usage after send message: 2090 KB Memory used: 245 KB ----< Thank you for using GreMes >---- ----< Press any key to exit >----“ Table 2 : Test Case.