Implement a complex ADT and algorithm in an executable programming language, Assignments of Data Structures and Algorithms

Implement a complex ADT and algorithm in an executable programming language to solve a well defined problem.

Typology: Assignments

2022/2023
On special offer
30 Points
Discount

Limited-time offer


Uploaded on 04/14/2023

trieu-nguyen-thanh
trieu-nguyen-thanh 🇻🇳

5

(1)

1 document

1 / 19

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 and Algorithms
Submission date
Date Received 1st submission
Re-submission Date
Date Received 2nd submission
Student Name
NGUYEN MINH DUC
Student ID
BH00270
Class
PBIT17103
Assessor name
NGO THI MAI LOAN
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
P1
P2
P3
M1
M2
M3
D1
D2
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
Discount

On special offer

Partial preview of the text

Download Implement a complex ADT and algorithm in an executable programming language and more Assignments Data Structures and Algorithms 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 and Algorithms Submission date Date Received 1st submission Re-submission Date Date Received 2nd submission Student Name NGUYEN MINH DUC Student ID BH Class PBIT17103 Assessor name NGO THI MAI LOAN 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 P1 P2 P3 M1 M2 M3 D1 D

Summative Feedback:Resubmission Feedback: Grade: Assessor Signature: Date: Internal Verifier’s Comments: IV Signature:

messages up to a maximum of 2 0 0 characters. The objective of the demo is to showcase the important operations of these structures, and ensure that the algorithms and operations are correct by executing various tests. It is essential that errors are handled carefully by exceptions to ensure the program runs smoothly. Our team will need to carefully design and implement the demo version, taking into consideration the key aspects of the ADTs and algorithms, to ensure that the system performs optimally.

B. Contents

P4. Implement a complex ADT and algorithm in an executable

programming language to solve a well defined problem.

a) What is “Queue Message”

  • In computer science, a "queue message" refers to a message that is stored in a queue, waiting to be processed by a receiving application or service. This type of message is commonly used in message-oriented middleware systems, where multiple applications or services need to communicate with each other asynchronously.
  • When sending a message through a buffer queue middleware system, the message is first placed into a queue, which serves as a buffer between the sender and receiver. The message can then be retrieved from the queue by the receiver, which can process the message and send a response if necessary. b) Processes of sending and receiving messages through Buffer Queue
  • Here are the steps involved in sending and receiving messages through a buffer queue middleware system:
    1. Sender application sends a message: The sender application sends a message to the buffer queue, which is then stored in the queue.
  1. Buffer queue stores the message: The message is stored in the buffer queue until it is retrieved by the receiver application.
  2. Receiver application retrieves the message: The receiver application retrieves the message from the buffer queue, which triggers the processing of the message.
  3. Receiver application processes the message: The receiver application processes the message and may send a response back to the sender through the buffer queue.
  4. Sender application receives the response: The sender application receives the response from the buffer queue, which can be used to determine the success or failure of the message processing.
  • Using a buffer queue middleware system provides a number of benefits, including improved reliability, scalability, and fault tolerance. By decoupling the sender and receiver applications, the middleware system can handle fluctuations in message volume and ensure that messages are processed in a timely and efficient manner. c) Executable Code
  • Executable code, also known as machine code or object code, refers to the code that is in a format that a computer can execute directly without further translation. It consists of a series of instructions written in binary code that the computer can understand and execute. Executable code is created when the source code of a program is compiled or assembled. It is the code that actually runs on the computer's processor and performs the operations specified in the program. Once the executable code is created, it can be loaded into memory and executed by the computer's operating system.

The code above is a Java program that implements a "Queue Message" system using the ADT (Abstract Data Type) of a queue and a stack. It provides a simple command-line menu for the user to input, send, and view messages. The program starts by defining a Message class that represents a message with a sender, recipient, and content. Next, a Queue class and a Stack class are defined, which are both implemented from scratch without using any Java libraries. The Queue class represents a queue data structure, which is used to store messages waiting to be sent, while the Stack class represents a stack data structure, which is used to store sent messages. The main program provides a menu with three options for the user:

d) Result

At first, I input 2 new messages are “nguyenminhduc2803” and “nguyenminhduc0000” After finished selection 1, I send message “nguyenminhduc2803” first and do it samely to “nguyenminhduc0000” later Finally, Press 3 to view all sent messages

P5. Implement error handling and report test results.

a) Definition try catch exception

  • Try-catch block is a mechanism to handle exceptions that may occur during the execution of a program. The try block contains the code that may throw an exception and the catch block contains the code that handles the thrown exception.
  • If an exception is thrown within the try block, the program jumps to the catch block that handles the specific type of exception that was thrown. If an exception is not thrown, the catch block is skipped.

c) Test cases No. Test case description Procedure Expected Result Result Status 1 Input messages Enter 6 input messages Display: Queue is full. Cannot add message Pass 2 Input messages Enter

characters message Error: Message maximum 200 characters Pass 3 Input messages Enter 201 characters message Error: Message maximum 200 characters Pass 4 Input messages Enter <,= 200 characters Display entered message and add to queue Pass 5 Enter menu choice Enter invalid choice Display exception: please enter valid choice Fail 6 Send message Send message without input message Display: Queue is empty Pass 7 View message View message without input or send Display: Stack is empty Pass 8 Input messages Input = null Display: Error, input can’t be null Pass 9 Exit program Exit program Display: Exiting program Pass

P6. Discuss how asymptotic analysis can be used to assess the

effectiveness of an algorithm

a) What is asymptotic analysis?

  • Asymptotic analysis is a method used in computer science and mathematics to analyze the performance of algorithms or functions. It involves studying how the running time or memory usage of an algorithm or function grows as the input size approaches infinity. The goal of asymptotic analysis is to provide a high-level understanding of the algorithm's performance and scalability, without being tied to a specific input size or hardware configuration.
  • Asymptotic analysis typically uses mathematical notation, such as big O notation, to describe the performance characteristics of an algorithm or function. For example, an algorithm with a time complexity of O(n^2) means that the running time grows quadratically with the input size n.
  • Asymptotic analysis is an important tool for comparing and evaluating algorithms and determining their suitability for different types of problems and inputs. By understanding the asymptotic behavior of an algorithm, we can make informed decisions about when to use it and when to consider alternative approaches. b) Why using asymptotic analysis for assessing the effectiveness of an algorithm?
  • Asymptotic analysis is used to assess the effectiveness of an algorithm because it provides an understanding of how the algorithm will perform on large input sizes. It helps to determine the time and space complexity of an algorithm and how these will scale as the input size increases. By evaluating the performance of an algorithm using asymptotic analysis, it is possible to determine the efficiency of the algorithm and to compare it to other algorithms. This allows us to select the most appropriate algorithm for a given problem and to optimize the performance of the algorithm.

example, if an algorithm has a time complexity of Ω(n), it means that the algorithm will take at least n steps to complete.

  1. Theta Notation (Θ): This notation represents both the upper and lower bounds of the growth rate of an algorithm. It denotes the average-case scenario in terms of time complexity. For example, if an algorithm has a time complexity of Θ(n), it means that the algorithm will take no more than n steps and at least n steps to complete.

P7. Determine two ways in which the efficiency of an algorithm can

be measured, illustrating your answer with an example.

a) How to measure the efficiency of an algorithm and examples to measure the efficiency of the algorithm. There are several ways to measure the efficiency of an algorithm, but two common ways are time complexity and space complexity.

  1. Time complexity: This measures the amount of time required by an algorithm to execute, as the size of the input increases. The time complexity of an algorithm is usually expressed in terms of Big O notation. For example, an algorithm that has a time complexity of O(n) means that the time taken to execute the algorithm increases linearly with the size of the input.

This Java code defines a method named findSum that takes an integer array arr as input and returns the sum of all elements in the array. The method first initializes a variable named sum to zero, which will be used to store the sum of all elements in the array. It then uses a for loop to iterate through each element of the array. The loop starts at index 0 and continues until it reaches the end of the array, which is indicated by the condition i < arr.length. Inside the loop, the current element of the array (i.e., arr[i]) is added to the current value of sum. This operation is performed repeatedly until all elements in the array have been processed. Finally, the method returns the value of sum, which represents the total sum of all elements in the array.

  1. Space complexity: This measures the amount of memory required by an algorithm to execute, as the size of the input increases. The space complexity of an algorithm is usually expressed in terms of Big O notation. For example, an algorithm that has a space complexity of O(n) means that the amount of memory required by the algorithm increases linearly with the size of the input. The code above is a method named "findMax" which takes an array of integers as input and returns the maximum value within the array.

Study.com. (2023). Available at: https://study.com/learn/lesson/algorithm-analysis-methods- types.html#:~:text=Asymptotic%20analysis%20is%20a%20way [Accessed 4 Apr. 2023].