Analysis of Message Queues & Search Algorithms: Understanding Data Structures & Algorithms, High school final essays of Computer science

The implementation of message queues and the assessment of data structure and algorithm effectiveness using the example of message transmission. It covers the theory behind message queues, the implementation of a message queuing program, and the comparison of linear search and binary search algorithms. The document also explores the importance of asymptotic analysis in evaluating algorithm performance and the trade-offs between time and space complexity.

Typology: High school final essays

2020/2021

Uploaded on 01/08/2022

jackie-ming
jackie-ming 🇬🇧

8 documents

1 / 36

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
ASSIGNMENT 2 FRONT SHEET
Qualification
BTEC Level 5 HND Diploma in Computing
Unit number and title
Unit 19: Data Structures & Algorithms
Submission date
August 28th,2019
Date Received 1st
submission
Re-submission Date
Date Received 2nd
submission
Student Name
Nguyen Ngoc Khanh
Student ID
GCD18376
Class
GCD0821
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
Nguyen Ngoc Phi
Grading grid
P4
P5
P6
P7
M4
M5
D3
D4
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c
pf1d
pf1e
pf1f
pf20
pf21
pf22
pf23
pf24

Partial preview of the text

Download Analysis of Message Queues & Search Algorithms: Understanding Data Structures & Algorithms and more High school final essays Computer science in PDF only on Docsity!

ASSIGNMENT 2 FRONT SHEET

Qualification BTEC Level 5 HND Diploma in Computing

Unit number and title Unit 19: Data Structures & Algorithms

Submission date August 28th,2019 Date Received 1st submission

Re-submission Date Date Received 2nd submission

Student Name Nguyen Ngoc Khanh Student ID GCD

Class GCD0821 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 Nguyen Ngoc Phi

Grading grid

P 4 P 5 P 6 P 7 M 4 M 5 D 3 D 4

Summative Feedback:Resubmission Feedback:

Grade: Assessor Signature: Date:

Internal Verifier’s Comments:

Signature & Date:

ASSIGNMENT 2

Data Structure And Algorithms

Version 0.

Change History

Version Date Author Description

0.1 August 23rd, 2019 Nguyen Ngoc Khanh Create new

INTRODUCTION This report will provide for you the knowledge about middleware, the relationship between MOM with ADT/ Algorithm, as well as, illustrated example for each terms. In addition, this report also give the way to assess the effectiveness of data structure and algorithms, and implement complex data structures and algorithms

LO1 Implement complex data structure and algorithms P4 Implement a complex ADT and algorithm in an executable programming language to solve a well- defined problem In this section we divided into two part, includes the theory about the message queue and a program that illustrate the message queuing. The aim of the split into two parts is helps understand the message queue specifically both in theory and practice. Basic theory of message queues What is a message queues? Figure 1 The message queue operation. To easily graphs what a message queues is, we must understand the term “Message” and “Queue” within it. The term “Queue” means a line of things waiting to be handle that follow sequential order starting at the beginning of the line. Besides, the data transported between the sender and the receiver application is called a message. In the basic means it is a byte array with some headers on top. A message queue is a is a queue of messages sent between application that includes a sequence of work objects that are waiting to be processed. In the shorten word, a message queue is a named destination to which message can be sent. Messages accumulate on queues until they are retrieved by programs that service those queues. A queue message gives an asynchronous communication protocol, a system that puts a message onto a message queue that does not require an immediate response to continuing processing. A queue manager is responsible for managing message queue. The physical nature of a queue depends on the operating system on which the queue manager is running. A volatile buffer area in the memory of a computer, or a data set on a permanent storage device such as a disk can be a queue. In additional, the physical management of queues is the responsibility of the queue manager.

Implement a complete ADT and algorithm to solve a well- defined problem Problem Build a program that allows the transmission of a message as a sequence of 250 source characters to the destination. The source side uses the queue to make the buffer and the destination side uses the stack to handle the string. Implement the application with source code in C Source code Figure 4 Code of creating a Message Queue. Figure 5 Code of get all the message queues.

Figure 6 Code to open the queue on the local server. Figure 7 Code to send a message.

Exception handling Exceptions provide better control over error handling Keywords related to exceptions:

  • Try - A function using an exception should be in a “try” block. If the exception does not trigger, the code will continue as normal.
  • Catch - “Catch” block retrieves an exception and creates an object containing the exception information. Implement error handling Report test result

Error Explain

Ignore syntax Write the wrong syntax that can lead the

algorithm can display

Lack of the library When developer with this code we lack of

some libraries

Don’t have access to queue on a Message

Queuing server

If you cannot implement code queue

when you don’t add refer System.

Messaging

M4 Demonstrate how the implementation of an ADT/ algorithm solves a-well defined problem Middleware is software that connects network-based requests created by the client to the back-end data that the client is requesting. Middleware is similar to an operating system because it can support other application

programs, provides controlled interaction, prevents interference between calculations and facilitates interaction between properties. math on different computers through network communication services. How it works? All network-based requests are basically trying to interact with data behind. That data can be something as simple as an image to display or a video to play or it can be complicated as a history of banking transactions. The requested data can be of different types and can be stored in different ways, such as coming from a file server, fetched from a message queue or stored in a database. The role of intermediary software is to allow and easily access those auxiliary resources. Some examples of middleware:  Distributed cache  Message queue  Transaction monitoring  Automatic backup system (Red hat, 2018) Why message queues intermediate? In addition, Middleware message queuing allows optimal handling of transactions. It is done by properly channeling transactions, prioritizing and allocating the appropriate amount of resources to handle them. By queuing, Middleware ensures that:

  1. The interaction between sending and receiving applications takes place as designed. If there is another problem or problem, the queue allows the messages to be (paused) and resent when the application receives online again.
  2. Accurate information in both applications, fully approved that transactions are handled appropriately.
  3. Nothing happens outside the normal process.

Asymptotic analysis is input bound, it means if there is not input to the algorithm, it is concluded to work in a constant time. In the other faces, the input all other elements are considered constant. Asymptotic analysis mention to computing the running-time of any operation in mathematical units of computation. Generally, the time required by an algorithm comprises the following three types:  Best Case: Minimum time required for program execution.  Average Case: Average time required for program execution.  Worst Case: Maximum time required for program execution. Asymptotic Notations A way of comparing function that ignores constant factors and small input sizes is called asymptotic notations. There are three commonly asymptotic notations that used to calculate the running-time complexity of an algorithm.  O Notation  Ω Notation  Θ Notation Big- oh (O) notation The formal method of expressing the upper bound of the running-time of an algorithm is Big-oh. It is the measure of the longest amount of time. The function f(n)= O(g(n)) is read as f of n is big-oh of g of n, if and only if exist positive constant c such that f(n) ≤ k.g(n)f(n)≤k.g(n) for n >n 0 n>n 0 Thus, function g(n) is an upper bound for function g(n) as g(n) grows faster than f(n) Figure 11 Asymptotic upper bound. For examples, a) 3n+2=O(n) as 3n+2≤4n for all n≥ 2 b) 3n+3=O(n) as 3n+3≤4n for all n ≥

So, the complexity of f(n) is represented as O(g(n)) Omega (Ω) Notation The function f(n)= Ω(g(n)) is read as f of n is omega of g of n, if and only if there exist positive constant c and n 0 such that f(n)≥k.g(n) for all n, n≥n 0 Figure 12 Asymptotic lower bound. For examples, f(n)= 8n^2 +2n- 3 ≥8n^2 - 3 = 7n^2 +(n^2 - 3)≥7n^2 (g(n)) Thus, k 1 = So, the complexity of f(n) represented as Ω(g(n)) Theta (θ) Notation The function f(n)=θ(g(n)) read as f is the theta of g of n, if and only if there exists positive constant k 1 , k 2 and k 0 such that k 1 .g(n)≤f(n)≤k 2 .g(n) for all n, n≥n 0 Figure 13 Asymptotic tight bound.

problem, it might also be possible that for some inputs, the first algorithm performs better on one machine and the second algorithm works better on other machine for some other inputs. To solve some problem that leaded by the naïve way, the asymptotic analysis is the ideal solution. By working within asymptotic analysis, we can evaluate the performance of an algorithm in term of input size, as well as, we calculate how does the time and space taken by an algorithm increase with the input size. For specially example, we consider the search problem in a sorted array. We have two different methods, once using Linear Search and second using Binary Search

  1. Linear Search Searching an element from array or linked list by examining each of the elements and comparing it with the search element starting with the first element to the last element in the list is called Linear search. If an elements is found then index, flag signal or value can be returned or processed, otherwise special index as - 1 or flag signal can be return. It scans the elements in a list in linear manner or in sequence by scanning one by one element in a list.  Time that required to search an element if exits or to determine that element is not found relies on the total number of elements in the list. Thus, the time complexity of Linear search is O(n) (JeanPaul Tremblay) (Ancy Oommen, Chanchal Pal, 2014)  The Worst case requires n comparison if an element is found at the last position of n or an element does not exist in the list  Average time that required by Linear search on an average we can say an element may be at center of the list, so the average time for this algorithm is O( 𝑛 2 ) which is again linear in nature.  The best case time is O(1) which is constant and elements is found at the first position.  Generally, the time required by Linear search is O(n) as Big-O notation is simply determines the highest order term and ignores the coefficients and lower order terms. So, it is simplest implementation and can be applied to array list, as well as, all types of linked list. However, it is not useful when the size of list is too large, cause the time require is proportional to total number of elements n. Thus, it is useful when we have small size of an array or a linked list but require more time when an array become large. An algorithm of linear search which finds the location of the search term if found otherwise the message of element not found is displayed. Algorithm LINEAR_SEARCH(V,N,X): Given a vector V containing N elements, this algorithm search V for give value of X. FOUND is Boolean variable, I and LOCATION are integer variables. [Search for the location of value X in vector V] FOUND ← false I ← 1 Repeat while I≤N and not FOUND If V[I]= X then FOUND← true LOCATION ← 1

Exit else I← I+ Write(“Value of”, X, “NOT FOUND”) [Finished] Exit The above algorithm searches vector starting from the first elements up to the last element in linear manner for searching element X. Each time an index variable I is increase to search next element. If an element does not exist in the vector then entire vector is scanned and then result in element not found. The time required by the above algorithm is O(n) that is linearly proportional to total number of elements in the list.

  1. Binary Search The problem about the performance of the linear happens when the number of element is too large. To solve this situation, the binary search is the ideal solution. The binary search algorithm can be applied to an array whose elements are to be required in sorted form (KNUTH, Mathematical analysis of algorithms,
    1. (Ancy Oommen, Chanchal Pal, 2014). Each iteration of binary search narrows the search interval by half of the search interval of its previous iteration.  The time required binary search is O(log 2 n) (KNUTH, Mathematical analysis of algorithms, 1997) (P PhyuPhyu Thwe, Lai Lai Win Kyi, 2014). Variation of binary search can be possible by selecting a random element between lower and upper bound. Function BINARY_SEARCH(K, N ,X): Given a vector K, includes N elements in ascending order, this algorithm searches the structure for a given element whose value is given by X. The variables LOW, MIDDLE and HIGH denote the lower, middle, and upper limits of the search interval. The function returns the index of the vector element if the search is successful and return 0 otherwise. [Initialize] LOW ← 1 HIGH ← N [Performa search] Repeat step 4 while LOW ≤ HIGH [Obtain index of midpoint of interval] MIDDLE ← (𝑳𝑶𝑾+𝑯𝑰𝑮𝑯) 𝟐 [Compare] If X < K [MIDDLE] Then HIGH ← MIDDLE - 1 Else if X > K [MIDDLE] Then LOW← MIDDLE+