Download Data Structures and Algorithms: Queue and Stack Implementation and more Assignments Introduction to Computing in PDF only on Docsity!
Assignment 2
Univerrsity of Greenwich Information Technology majors
By : Lê Tấn Đạt
Student ID: GCD
DATA STRUCTURES &
Content
P4. Implement a complex ADT and algorithm in an executable programming language to solve a well defined problem………...……….…………................ 1.Queue of messages.………………………………………………………….
2. Stack of messages……………….………………………………………….. P5. Implement error handling and report test result………......…………….. P6.Discuss how asymptotic analysis can be used to assess the effectiveness of an algorithm………………………………………………………………...…… P7. Determine two ways in which the efficiency of an algorithm can be measured, illustrating your answer with an example……………………….... M4. Demonstrate how the implementation of an ADT/algorithm solves a well- defined problem…………………………………………...……………………. M5 Interpret what a trade-off is when specifying an ADT using an example to support your answer…………………………………………………………….
- Operations with stack data structures are:
- push: add a record
- pop: take the same record
- length: returns the number of records
- peak: Return to the first record
- Application of stack:
- Convert decimal numbers to binary
- Calculate the suffix algebraic expression value Example 1: Suppose you would like to check if the queue exists and if it does, send a message to it. If the queue doesn't exist, you may want to create a new one and then send it a message. static void Main(string[] args) { MessageQueue messageQueue = null; string description = "This is a test queue."; string message = "This is a test message."; string path = @".\Private$\IDG"; try { if (MessageQueue.Exists(path)) { messageQueue = new MessageQueue(path); messageQueue.Label = description;
else { MessageQueue.Create(path); messageQueue = new MessageQueue(path); messageQueue.Label = description; } messageQueue.Send(message); } catch { throw; } finally { messageQueue.Dispose(); } } Source of code : (https://www.infoworld.com/article/3060115/how-to-work- with-msmq-in-c.html)
Here is result
Reference source for implementing code : (https://www.codeproject.com/Articles/1260171/Message-Queue-2)
2) Stack of messages
- The message stack comprises three main modules: Message, Message Notify, and Message Subscribe.
- The modules have been written with a pluggable architecture that supports customization and extensibility. Each module includes implementation examples that give a hint of the potential use cases and integration with other popular Drupal modules. Source : (https://www.drupal.org/node/2180145)
- Operations with queue data structure:
- EnQueue: Add a record at the end of the queue
- DeQueue: Get the first record
- IsEmpty: Check whether the queue is empty or not
- Front: Return to the first record
- The queue application
- Handling commands in the computer
- Checking Palindrome strings: A string is called a Palindrome property if it is symmetric. To check this property of any string, we read the string by two separate structures, the stack, and queue. Then, retrieve each element in the stack and queue to compare each other. If all elements in the stack are the same as the element in the queue in the corresponding position, the string has a Palindrome property.
Example 2: The following is an example showing how to work with Stack class and its Push() and Pop() method:
P5 Implement error handling and report test results. Number Bug/Errors Date
1 It displays an error message when compiling 11/5/
2 Cannot communicate information (have a hole in the link area) 11/5/
3 Errors generated from referencing a null object. 11/5/
4 Do not execute code, insert the wrong object. 11/5/
P6 Discuss how asymptotic analysis can be used to assess the effectiveness of an algorithm.
- Asymptotic analysis of an algorithm refers to defining the mathematical boundation/framing of its run-time performance. It tries to estimate the time as a function of the input size. For example, when analyzing the worst case running time of a function that sorts a list of numbers, we will be concerned with how long it takes as a function of the length of the input list.
- Asymptotic analysis is input bound if there's no input to the algorithm, it is concluded to work in constant time.
- Asymptotic analysis refers to computing the running time of any operation in mathematical units of computation. For example, the running time of one operation is computed as f(n) and maybe for another operation, it is computed as g(n2). This means the first operation running time will increase linearly with the increase in n and the running time of the second operation will increase exponentially when n increases. Similarly, the running time of both operations will be nearly the same if n is significantly small.
- Also, in Asymptotic Analysis, we always talk about input sizes larger than a constant value. It might be possible that those large inputs are never given to your software and an algorithm which is asymptotically slower, always performs better for your particular situation. So, you may end up choosing an algorithm that is Asymptotically slower but faster for your software. P7 Determine two ways in which the efficiency of an algorithm can be
measured, illustrating your answer with an example.
- The time efficiency and space efficiency depend on several things, including:
- The quality of the code;
- The nature of the processor
- The input data. **We have two ways of measuring algorithms as follows:
- Time efficiency - a measure of amount of time for an algorithm to** execute:
- Time efficiency is a function describing the amount of time an algorithm takes in terms of the amount of input to the algorithm. "Time" can mean the number of memory accesses performed, the number of comparisons between integers, the number of times some inner loop is executed, or some other natural unit related to the amount of real-time the algorithm will take.
- When analyzing for time complexity we can take two approaches: a) Theory:
- Analyze the algorithm, typically using time complexity analysis to get an estimate of the running time as a function of the size of the input data.
- Estimation of running time :
- Method 1 Operation counts : select operation(s) that are executed most frequently and determine how many times each is done.
- Method 2 Step counts: determine the total number of steps, possibly lines of code, executed by the program.
- The actual running time depends on many factors:
- The speed of the computer: CPU (not just clock speed), I/O, etc.
- The compiler, compiler options.
M4 Demonstrate how the implementation of an ADT/algorithm solves a well-defined problem
- Middleware is computer software that provides services to software applications beyond those available from the operating system. It can be described as "software glue"
- Middleware makes it easier for software developers to implement communication and input/output, so they can focus on the specific purpose of their application.The name middleware stems from the fact that it is the software that sits between the client-side request on the front end and the back-end resource being requested.
- With network-based interactions, a client, or requesting a program, can make a request. That client is typically an application that resides on the front end, which is where the user interacts with software. Resources such as databases, message queues, NoSQL data stores, and file servers are often referred to as being part of the back end.
- Middleware serves a variety of functions.
- First, it manages connectivity to various back-end resources. So, a middleware component might create a connection pool to provide fast and efficient access to a popular back-end database.
- Second, middleware software has the capacity to implement logic based upon the request made from the client.
- Third, middleware plays an important role in concurrent processing, load balancing, and even transaction management.
- A data structure strives to provide many useful, efficient operations. But there are unavoidable trade-offs:
- Time vs. space
- One operation more efficient if another less efficient
- Generality vs. simplicity vs. performance
- A space-time or time-memory trade-off in computer science is a case where an algorithm or program trades increased space usage with decreased time. Here, space refers to the data storage consumed in performing a given task (RAM, HDD, etc), and time refers to the time consumed in performing a given task (computation time or response time). If data is stored uncompressed, it takes more space but less time than if the data were stored compressed. Larger code size can be used to increase program speed when using loop unwinding. This technique makes the program code longer for each iteration of a loop but saves the computation time needed for jumping back to the beginning of the loop at the end of each iteration.
- Example, the utility of a given space-time tradeoff is affected by related fixed and variable costs (of, e.g., CPU speed, storage space), and is subject to diminishing returns.
- The one-pass (or streaming) model. In this setting, the elements of the input can only be scanned once in a sequential fashion.Allow input to be scanned any number of times and even allowing random access to the input values. Research for this model focuses on either computability (i.e., determining whether or not a particular problem is solvable with a workspace of fixed size) or the design of efficient algorithms whose running time is not much worse (when compared to the case in which no space constraints exist).