
















Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!

















Qualification BTEC Level 5 HND Diploma in Computing Unit number and title Submission date Date Received 1st submission Re-submission Date Date Received 2nd submission Student Name Pham Lam Thai Student ID BHAF Class PBIT17102 Assessor name Nguyen Thai Cuong 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 Grading grid P4 P5 P6 P7 M4 M5 D3 D
Grade: Assessor Signature: Date: Internal Verifier’s Comments: IV Signature:
effectiveness. I'll also provide a measurement for an algorithm's efficiency, and I'll use that to illustrate your response. II. Implement a complex ADT and algorithm in an executable programming language to solve a well-defined problem (P4).
1. What’s Queue Message The Message Queue is a Queue, containing many Messages. You can understand message queue as a mailbox, allowing components/services in a system (or multiple systems), to send information to together. The reason why it is called a queue is that it performs message retrieval according to the FIFO mechanism – First In First Out.
2. Common Components A system using Message Queue typically has the following components: Message: The message is sent (can be text, binary or JSON) Message Queuing: A place where these messages are stored, allowing producers and consumers to communicate with each other Producer: Program/service that generates information, puts it in a message queue Consumer: The program/service that receives the message from the message queue and processes it A program/service can be both a producer and a consumer 3. Executable Code This programming includes: Use ADT Queue) as a buffer during data transmission and reception. Error handling: use Exception catcher - "try...catch" block to catch and handle errors if any arise during program execution. Test program and report test results (Test case, test log). To solve this problem, I designed the ADT Queue to handle requests as follows: So, I will use Queue to solve the above problem. First, I create a Message class, and where will receive date that includes the following objects:
Next, Here will Main class where contain mainly content of code:
Now, I will run the program so you understand how it work.
The above that I use the function to add message to the Queue and now I will try to display it on the screen. I just need to enter Name and Message to display on screen. Next, I will try to delete function. Output:
The try and catch keywords come in pairs When implementing the system, we will encounter some errors like this: As you can see, in the Menu above I allowed the user enter their options by number, similar the NextInt(), but if the user enter letter or any type is not number, the system will be given an error above as the program will be stopped immediately. So, after knowing that error, I used try catch keyword to fix it and you can see the following below:
2. Test Cases Test case Input data Expected output Actual output Status If the user enter their selection by number 1,2,3,4 If true, the system will be allowed enter Name and message successfully Pass If the user enters their selection by letter A,b,c,d or any letter that does not number The system will be announced an error The system will be announced an error Pass The user enters their message Character > 250 The system will announce an error that not allowed enter than the letter 250 One will announce an error and force the user to re- enter correctly Pass If the user adds multiples message More 1 or 2 message The Queue is full The Queue is full Pass If the user want to delete message Choice number 3 Delete successfully Delete successfully Pass If the user want to exit Choice number 4 “BUILD SUCCESSFUL (total time: 2 seconds) ”
(total time: 2 seconds) ” Pass My detail code will be posted on GitHub and this is my GitHub link: https://github.com/Phamlamthai/ASM2_DSA_PLT IV. Discuss how asymptotic analysis can be used to assess the effectiveness of an algorithm (P6). An algorithm is a set of clearly specified simple instructions to follow in order to solve a problem. Once an algorithm is given for a problem and decided (somehow) to be correct, an important step is to determine how much in the way of resources, such as time or space, the algorithm will require. An algorithm must be correct. It should correctly solve the problem. For example, for sorting, this means even if (1) the input is already sorted, or (2) it contains repeated elements. To analysis an algorithm we need some kind of syntax, and that forms the base for asymptotic analysis/notation. There are three types of analysis:
The growth rate for an algorithm is the rate at which the cost of the algorithm grows as the size of its input grows. Time complexity Name For example 1 Constant Insert an element to the front of linklist logn Logarithmic Finding an element in sorted array nlogn Linear logarithmic Sorting n item by “ divide and conquer “ Merger sort N^2 Quadratic Shortest path between two nodes in a graph N^3 Cubic Matrix multiplication N Linear Finding an element in unsorted array 2^n Exponential The tower of Hanoi problem Now consider in the figure below:
The graph in the graphic above represents six equations, each of which describes how long a program or algorithm will execute. Various representative growth rates for the common algorithms are displayed. Straight lines are used to represent the graph of the two equations, 10n and 20n. The linear growth rate or run time is a common name for the growth rate cn (with any positive constant c). This implies that the algorithm's execution time grows proportionally as the value of n does. The running time will double if n is doubled in value. An algorithm is said to have a quadratic growth rate if the highest-order term in the running-time equation has the factor n2. The difference between an algorithm whose running time has a cost T (n) = 10n and another whose cost T (n) = 2n2 becomes significant as n rises, as seen in the figure above. The approach with T (n) = 2n2 running time was substantially slower for n> 5. This is true even though the constant coefficient of 10n is higher than that of 2n2. Changing the constant coefficient for one of the equations just alters the place where the two curves cross, as can be seen by comparing the two curves labeled 20n and 2n2.
b. Omega-Notation(Ω) Omega notation represents the lower bound of the running time of an algorithm. Thus, it provides the best case complexity of an algorithm. Let g and f be the function from the set of natural numbers to itself. The function f is said to be Ω(g), if there is a constant c > 0 and a natural number n0 such that cg(n) ≤ f(n) for all n ≥ n c. Theta-O Notation Theta notation encloses the function from above and below. Since it represents the upper and the lower bound of the running time of an algorithm, it is used for analyzing the average-case complexity of an algorithm. Let g and f be the function from the set of natural numbers to itself. The function f is said to be Θ(g), if there are constants c1, c2 > 0 and a natural number n0 such that c1 g(n) ≤ f(n) ≤ c2 * g(n) for all n ≥ n
The above expression can be described as if f(n) is theta of g(n), then the value f(n) is always between c1 * g(n) and c2 * g(n) for large values of n (n ≥ n0). The definition of theta also requires that f(n) must be non-negative for values of n greater than n0. A simple way to get the Theta notation of an expression is to drop low-order terms and ignore leading constants. For example, Consider the expression 3n3 + 6n2 + 6000 = Θ(n3), the dropping lower order terms is always fine because there will always be a number(n) after which Θ(n3) has higher values than Θ(n2) irrespective of the constants involved. For a given function g(n), we denote Θ(g(n)) is following set of functions.