BTEC FPT INTERNATIONAL COLLEGE ‘BTEC @ Pearson Alliance with Ga Education INFORMATION TECHNOLOGY ASSIGNMENT 2 UNIT: DATA STRUCTURES AND ALGORITHMS STUDENT : PHAM PHU LOC CLASS : IT05201 STUDENTID : BD00053 SUPERVISOR : PHAN HOANG PHÙ Da Nang, December 2023 ‘BTEC asance win gig Eaton ‘BTEC ASSIGNMENT 2 FRONT SHEET Qualification BTEC Level 5 HND Diploma in Computing Unit number and title Unit: Data Structures and Algorithms Date received (1st Submission date 25/11/2023 30/11/2023 submissionfi Date received (2nd Re-submission date submissionfi Student name Pham Phu Loc Student ID BD00053 Class IT05201 Assessor name Phan Hoang Phu Student declaration | certify that the assignment submission is entirely my own work and | fully understand the consequences of plagiarism. | understand that making a false declaration is a form of malpractice. Student’s signature: Phu Loc Grading grid P4 P5 Pó P7 M4 M5 D3 D4 SB : summative Feedbacks: MResubmission Feedbacks: Grade: Assessor Signature: Date: Internal Verifier’s Comments: Signature & Date: PAGE \* MERGEFORMATv ‘BTEC ae $‘BTEC TABLE OF CONTENT I5 2929900217272 5. ii LIST OF TABLES AND FIGURES.-- LH HH HH HH KH KH KH ky iv LIST OF ACRONYM.
LH HH HH KH HH HH KH TH T05 KH V00 Vv | (998509 1. 1 CHAPTER 3: IMPLEMENT COMPLEX DATA STRUCTURES AND ALGORITHMS. Implement a complex ADT and algorithm in an executable programming language to solve a Well-defined problem. Define Message QUEUE.
lImplementation Mlessage QUe€U€. QQ LH TH HH TH kg HH ng và 2 CHAPTER 4: ASSESS THE EFFECTIVENESS OF DATA STRUCTURES AND ALGORITHMS. Discuss how asymptotic analysis can be used to assess the effectiveness of an algorithm 4. Define asymptotÏC aniaÌVSÏS.- c c HH HH TH HH HH TT ng 1 TH KT n0 kg ng 3 1.
The reason of using asymptotic analysis for assessing the effectiveness of an E1 0c. Determine two ways in which the efficiency of an algorithm can be measured, illustrating your answer with arn example. ốc ốố ố ốằằồ. 1111 HS T110 11 1H ng ng ng TH T00 118001150 4 2.
Án Hà HH HH» HH HH KT KH HH KH TT 4 2. Measure of memOorY US4ÿ€. LH TggnngkHT ng n kg g kg 4 2. ốc ốố ố ốằằồ.
1111 HS T110 11 1H ng ng ng TH T00 118001150 4 PAGE \* MERGEFORMATv ‘BTEC nine win IG ean s ‘BT ï EC 2. 7 PAGE \* MERGEFORMATv ‘BTEC ae $‘BTEC LIST OF TABLES AND FIGURES B150 //—-2-19)/ 0-88. 2 Figure 2 Algorithm flowchar†t of MenU.-c SH n HH ng ng TH nen 3 Figure 3 Source code of MenU. ch TH HT TH TH KH HH g0 kg gyy 4 Figure 4 Algorithm flowchart of Input† ÌMesSag€.
Là HH HH ng ng khen fi Figure fi Source code of Input MI©SSaÿ6. Q HnnnnnHnn HH ng ng ng ng ng kg fi Figure ó Algorithm flowchart of Send Mlessage. LHng HH nh kh ó Figure 7 Source code of Send Ml€SS4E6. LH ng ng TH ng KT kg TH kg 7 Figure 8 Algorithm flowchart of View Latest ÌMes54aỹ.
HH HH HH hờ 7 Figure 9 Source code of View Latesf Mes548€. HH HH HH ng nen ng kg 8 Figure 10 Resul† OÍ COd. c L LH HS HH TH HT ng HT nh ng ng kh 9 B1i-xif9e. 11 Figure 13 Code số.
12 Figure 1fi SOUFC€ COdE. LH ng ng vn HH vế 12 Figure 16 OULPULL 0. 13 Figure 18 SOUrCE COE. 1fi FIQUrE 22 OULPULL 0.
cececccsesecccsesesnecccssneeeceseeseeeesssaeceseeecesecessseeessaeecssaeeecsseeaeeceecseaeeaeesseeenees 1fi Figure 23 Big-O Notationn.ccccescsccsssccssccssseeccsssecneeccssseeceesecesecesssaeeceseeceeneeeesaeseaeeesenaeeenens 18 PAGE \* MERGEFORMATv ‘BTEC ae $‘BTEC Figure 24 Omega No†tafÏOn.- LH HH ng ng ng TH HH HH ng kg 19 IBI1I1-02INÌ0 5-8) sr-i ii 0n. 20 Figure 2ó SourC€ COd€. HH ng ng HT kg HT n1 gà 21 B11-220--10i 108. 22 Figure 30 Tỉne cormpÏ€XỈÏÊY.
c c ng ng TH KT ki ng TH TH kg kg 24 H30i-£cx NI 0n 1900087. 24 Figure 32 Example Of O(1n).ccccccsccsssccssesscsceseesscesecsensecescsesesssescseeesscesesassecessssesessseeseeesseseaas 2fi đ20-£cc@vš i09 6000876. 2fi Figure 34 Example 1e896 005677. 2fi Figure 3fi Logarithmic tine O(lOg n).
Là L1 HH 11011011111 111g HH Hà HH Hà hy 26 B30-c c9 10)19i-0e89)(e-8)) 0010887. 27 Figure 39 Linear - Logarithmic tine OÍn lOg n). ác 1 c 1211111 1 11111111111811111 11118111 1k 28 Figure 40 Example of O(n ÍOg n). c 1 1111111111 11111011111 11011111 111811 11 E1 11H HH Hà cry 28 B109.
29 Figure 4fi Code demo. LH ng ng TH 00 9 kg về 30 B0 /. 31 PAGE \* MERGEFORMATv ‘BTEC _ la “BTEC B129. 31 Figure FIO OULPUL.
31 Figure fil Example of space COMPIEXILY.cceccccssccssseecceesseseeecesnsecceseeessnaeeeaeecnseeeseeeeneeeeees 33 Figure fi2 Example of space compDÌ€XỈTY. ch ng ng kg HH ghế 33 B1i-0iES2v0s-2››- nh. 34 PAGE \* MERGEFORMATv 5 “BTEC Alaxe win BIg ecaton ‘BTEC LIST OF ACRONYM ADT Abstract Data Types cLI Command-Line Interface FIFO First In First Out HTTP Hypertext Transfer Protocol JML Java Modeling Language LIFO Last In First Out MERN MongoDB, Express.js, React JS, and Node.js MEVN MongoDB, Express, Sue, and Node.js SOAP Simple Object Access Protocol PAGE \* MERGEFORMATv ‘BTEC Alliance with BG |, Education ‘BTEC INTRODUCTION First of all, | would like to thank my mentor Phan Hoang Phu for his constant support in my studies and research, for his patience, motivation, enthusiasm and rich knowledge. Without your wonderful help, | would not have been able to achieve this.
I'm employed at Soft net Development Ltd, a software company that specializes in networking solutions, as an internal software developer. My business has been awarded the contract to design and implement a middleware solution that will front-end with several interfaces as part of a service delivery partnership project. The computer provisioning interface consists of SOAP, HTTP, JML, and CLI, while the back end uses CLI for networking with telecommunications providers. | have been given a unique responsibility by my account manager to educate my staff on the creation and use of abstract data types.
| was requested to do a presentation on how to utilize ADT to enhance software design, development, and testing for all of the cooperating partners. | was also asked to prepare an introduction report on how to formalize the specification of abstract data types and algorithms for distribution to all partners. Let's find out in this assignment! “¢ Chapter 3: Implement complex data structures and algorithms. “* Chapter 4: Assess the effectiveness of data structures and algorithms Performed Student: Pham Phu Loc ‘BTEC ane wih IG ean $ ‘BT h EC CHAPTER 3: IMPLEMENT COMPLEX DATA STRUCTURES AND ALGORITHMS.
Implement a complex ADT and algorithm in an executable programming language to solve a well-defined problem. Define Message Queue A queue is a line of items waiting to be handled, starting at the front of the line and processing it sequentially. In essence, a message is a byte array with some headers at the topff it is the data that is carried between the sender and the receiving program. A message queue offers an asynchronous communications protocol, which is a system that adds a message to a message queue but does not need a prompt reply to continue processing.
Email is a good example of a Message Queue. Queue (eropucer_) |__| =>) (mm) Figure 1 Message Queue 1.2 Scenario overview The conveyance and processing of messages between layers is one aspect of the provider interface for the middleware that is currently under development. For transport, a buffer of queued messages is deployed and processed, the system requires a stack of messages. It is necessary to develop these types of collections for the system.
It is recommended to design an ADT/algorithm for these 2 structures and implement a demo version with the message as a string of up to 2fi0 characters. Handle the problems and errors encountered in the demo carefully with exceptions and some tests should be done to prove the correctness of the algorithms/operations. From the requests that have been made, | have selected two suitable ADT types to deal with, namely Stacks and Queues. - The stack will be used to store process messages.
- Queues are used to store the messages being transported. Performed Student: Pham Phu Loc 2 ‘BTEC nine win IG ean s ‘BT ï EC 1.1 Source code Menu In the main menu, there will be 4 functions: input message, send message, view message, and exit. Those four functions will correspond to the number from 1 to 4. Select the function you want to perform and enter its corresponding number to run the program.
Algorithm flowchart: Start | Input n lfn= 1 —yes—> lnputMessage —— No! n=2 —yes—» SendMessage —> No "=3 —_ ViewLatet .Ì Message Y No No L——— n=4 | yes Exit Ỷ End «————————— Figure 2 Algorithm flowchart of Menu Source code: Performed Student: Pham Phu Loc ‘BTEC Alliance with 88g 9 Education 8 public class asm2 { static Queue<String> messageStore = new LinkedList<>(); SBTEC 10 static Stack<String> messageConsumer = new Stack(); 11 128 public static void main(String args[]) { int choice = 0; 14 Scanner sc = new Scanner(System.in); 15 do { 16 System. Input Message"); 19 System. Send Message"); 20 System. View Latest Message"); 21 System.
Exit"); 22 23 boolean err = false; 24 do { 25 try { 26 System.print("Choose a number from 1 to 4: "); 27 choice = Integer.println("Please input number format!"); 31 if 32 if (choice > @ && choice <= 4) { 33 err = true; 34 } 35 else { 36 System.println("Please input number from 1 to 4!"); 37 } 38 } 39 while (err == false); 41 //choose 42 switch (choice) { 43 case 1: { 44 addMessage(); 45 break; 46 } 47 case 2: { 48 sendMessage() ; 49 break; 59 } 51 case 3: { 2 viewMessage(); 53 break; 54 } 55 default: 56 System.print1n("Exit"); 57 break; 58 } 59 } while (choice < 4); Figure 3 Source code of Menu Input Message Algorithm Step 1: Input a message below 2fi0 characters Step 2: Store a message to queue Performed Student: Pham Phu Loc 4 eee SB Step 3: Break ‘BTEC Algorithm flowchart: Start Input Message ert |a ng Display the message: “Input Message Failed! <yes— If Message= 250 if Message is empty >-—yes> Display oe the Gaerne message aS Messages can only contain characters ge SE Bo Kr" 250 characters” lank† No No Store a message to queue End Figure 4 Algorithm flowchart of Input Message Source code: //Input Message nan a) SOSIBDARANHPSHCHUARHEWN e public static void addMessage() { Scanner sc = new Scanner(System.in); String ms = ""; Dan System.print("Input Message: "); ms = sc.nextLine(); try { if (ms.isEmpty()) { #98%%Đ%£Ø%BP®SWaNðbQRwWNns8 throw new Exception("Message cannot be blank!"); } else { try { if (ms.length() > 250) { throw new Exception("Input Message Failed! Messages can only contain 25@ characters"); } else { messageStore.println("messageStore: +messageStore); } } catch (Exception e) { gE Wore System.getMessage()); } } } catch (Exception e) { sô IAA System.getMessage()); } ~ Figure 5 Source code of Input Message Performed Student: Pham Phu Loc 5 Py „° “BTEC “BT EC ° Alliance with GG. Education Send Message Algorithm Step 1: Check if there are already messages in the queue Step 2: If yes, retrieve the message in the first line of the queue Step 3: Push messages to consumers Step 4: Break Algorithm flowchart: Start nh Send Message Input Message † Y Display the message “MessageStore is empty! if there are no message Please input a in the queue yet messageStorel" | No Vv Send the first message in the queue to the consumer * End Figure 6 Algorithm flowchart of Send Message Source code: Performed Student: Pham Phu Loc 6 “BTEC _ ¬ aaa bon ‘BT ï E Cc 89 //Send Message 30° public static void sendMessage() { 1 if (messageStore.println("MessageStore is empty! Please input messageStore!"); 93 } 94 else { 95 String ms = messageStore.println("View Latest Message Consumer: " +messageConsumer.peek()); 104 } Figure 9 Source code of View Latest Message 1.