Tải bản đầy đủ (.pdf) (48 trang)

Asm 02 data structure

Bạn đang xem bản rút gọn của tài liệu. Xem và tải ngay bản đầy đủ của tài liệu tại đây (2.81 MB, 48 trang )

Data Structures and
Algorithms
ASSIGNMENT 02

Study’s Name : Huỳnh Trần Anh Khoa – GCS200252
CLASS: GCS0903A | SUBJECT CODE: 1649


ASSIGNMENT 2 FRONT SHEET
Qualification

BTEC Level 5 HND Diploma in Computing

Unit number and
title

Unit 19: Data Structures and Algorithms

Submission date

June 26th 2022

Date Received 1st submission

June 26th 2022


Re-submission Date

Date Received 2nd submission


Student Name

Huỳnh Trần Anh Khoa

Student ID

GCS200252

Class

GCS0903A

Assessor name

Lê Văn Thành

Student declaration

I certify that the assignment submission is entirely my own work and I fully understand the consequences of plagiarism. I u
false declaration is a form of malpractice.
Student’s signature
Grading grid
P4

P5

P6

P7


M4

M5

D3

D4


 Summative Feedback:

Grade:

 Resubmission Feedback:

Assessor Signature:

Date:

Internal Verifier’s Comments:

IV Signature:

1


Assignment Brief 2 (RQF)
Higher National Certificate/Diploma in Business
Student Name/ID Number:


Huỳnh Trần Anh Khoa – GCS200252

Unit Number and Title:

Unit 19: Data Structures and Algorithms

Academic Year:

2021

Unit Assessor:
Assignment Title:

Implement and assess specific DSA

Issue Date:
Submission Date:

June 26th 2022

Internal Verifier Name:
Date:

Submission Format:
Format:
● The submission is in the form of an individual written report and a presentation. This should be
written in a concise, formal business style using single spacing and font size 12. You are required
to make use of headings, paragraphs and subsections as appropriate, and all work must be
supported with research and referenced using the Harvard referencing system. Please also provide
a bibliography using the Harvard referencing system.

Submission
● Students are compulsory to submit the assignment in due date and in a way requested by the
Tutor.
● The form of submission will be a soft copy posted on />● Remember to convert the word file into PDF file before the submission on CMS.
Note:
2


● The individual Assignment must be your own work, and not copied by or from another student.


If you use ideas, quotes or data (such as diagrams) from books, journals or other sources, you
must reference your sources, using the Harvard style.

● Make sure that you understand and follow the guidelines to avoid plagiarism. Failure to comply
this requirement will result in a failed assignment.
Unit Learning Outcomes:
LO3 Implement complex data structures and algorithms
LO4 Assess the effectiveness of data structures and algorithms
Assignment Brief and Guidance:
Assignment scenario
Continued from Assignment 1.
Tasks
For the middleware that is currently developing, one part of the provision interface is how message can
be transferred and processed through layers. For transport, normally a buffer of queue messages is
implemented and for processing, the systems requires a stack of messages.
The team now has to develop these kind of collections for the system. They should design ADT /
algorithms for these 2 structures and implement a demo version with message is a string of maximum
250 characters. The demo should demonstrate some important operations of these structures. Even it’s a
demo, errors should be handled carefully by exceptions and some tests should be executed to prove the

correctness of algorithms / operations.
The team needs to write a report of the implementation of the 2 data structures and how to measure the
efficiency of related algorithms. The report should also evaluate the use of ADT in design and
development, including the complexity, the trade-off and the benefits.

3


Learning Outcomes and Assessment Criteria (Assignment 2)
Pass

Merit

Distinction

LO3 Implement complex data structures and algorithms
P4 Implement a complex ADT
and algorithm in an executable
programming language to solve
a well defined problem.

M4 Demonstrate how the
implementation of an
ADT/algorithm solves a welldefined problem

D3 Critically evaluate the
complexity of an
implemented
ADT/algorithm


P5 Implement error handling
and report test results.

LO4 Assess the effectiveness of data structures and algorithms
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.

M5 Interpret what a trade-off is
when specifying an ADT using
an example to support your
answer

4

D4 Evaluate three benefits of
using implementation
independent data structures


Table of Contents
Table of Contents
Assignment Brief 2 (RQF) ......................................................................................................2
Higher National Certificate/Diploma in Business ...................................................................2

Table of Contents ...................................................................................................................5
P4 Implement a complex ADT and algorithm in an executable programming language to solve a
well defined problem. .............................................................................................................6
1) Introduction .................................................................................................................6
2) Implement ADT ...........................................................................................................6
The given scenario is: ......................................................................................................6
To address a well-defined problem, implement a complicated ADT and algorithm in an
executable programming language. ...................................................................................7
Design the ADT and algorithm .........................................................................................8
P5 Implement error handling and report test results. .................................................................17
1) Error Handling ...........................................................................................................17
2) Test Result .................................................................................................................19
P6 Discuss how asymptotic analysis can be used to assess the effectiveness of an algorithm. .......23
Discuss how asymptotic analysis can be used to assess the effectiveness of an algorithm .........24
1) The execution time of algorithm ...............................................................................24
2) Asymptotic analysis ................................................................................................27
3) General Rules for Estimation ....................................................................................31
P7 Determine two ways in which the efficiency of an algorithm can be measured, illustrating your
answer with an example. .......................................................................................................34
1) Time complexity ........................................................................................................35
2) Space Complexity.......................................................................................................36
3) Evalutte .....................................................................................................................39
Stack:...........................................................................................................................39
Queue: .........................................................................................................................41
Conclusion ..........................................................................................................................44
Reference ............................................................................................................................44

5



P4 Implement a complex ADT and algorithm in an
executable programming language to solve a well
defined problem.
1) Introduction
Algorithms with varying degrees of inefficiency can frequently solve the same task.
When an algorithm is presented for a problem and (somehow) proven to be accurate,
one critical step is determining how much time or space the method would require.
This assignment includes the following components of my report:
• First, I will apply a complicated ADT and technique to a well-defined problem
in Java programming.
• Second, I'll implement error handling and report on the results of the tests.
• The success of an algorithm may be evaluated using asymptotic analysis,
which I'll discuss in my last part.
Finally, I'll present two alternative approaches for assessing the success of an
algorithm, along with real examples.

2) Implement ADT
The given scenario is:
“One aspect of the provider interface for the middleware that is presently being
developed is how messages may be transported and processed via layers. Typically, a
buffer of queued messages is used for transit, and a stack of messages is used for
processing.
The team must now create these types of collections for the system. They should
create ADT / algorithms for these two structures and construct a sample version with
a message of no more than 250 characters. The demonstration should show some of
these structures' most significant operations. Even if it's only a demo, failures should
be handled properly using exceptions, and certain tests should be run to demonstrate
the validity of algorithms and operations.”
The supplied scenario suggests that we require some relevant ADTs to handle this
issue. The words stack and queue are described in Assignment 1.

• The stack is used to save process messages.
• A queue is used to hold the messages that have been transported.

6


To address a well-defined problem, implement a complicated ADT
and algorithm in an executable programming language.
A stack is a linear data structure that can only be accessed at one of its ends for
storing and retrieving data. New trays are put on top of the stack and taken from the
top, much like a stack of trays in the cafeteria. The first tray removed from the stack
is the one that was most recently inserted. The outcome is the Last in First Out
(LIFO) or First in Last Out (FILO) list. As a result, the process messages are stored in
Stack.
A queue is just a collection of objects that may expand by adding items at the end and
contract by deleting ones from the beginning. In contrast to a stack, a queue is a
structure in which components may be added and deleted from both ends. As a result,
the last element must wait until every element in the queue has been wiped before
being erased. As a result, it is often referred to as a Last on Last out (LILO) or a First
in First Out (FIFO) list. As a result, the transferred messages are queued. The
message will be added to the queue, but it will not be added if the queue is already
full.

7


Figure: Message Flowchart

Design the ADT and algorithm
To tackle this problem, I created the following classes: "Sender class"—to send the

message from Kelbin to Rosé—and "Receive class"—to receive the message and
display it on the console using Queue ADT and Stack ADT.

8


Sender Class: This class method takes O(1) time to complete.

9


Receive class: This class method takes O(1) time to complete.

Next Create a Queue Class:
10


11


12


Stack Class: This class method takes O(1) time to complete.

13


Finally, I will create a Program class for the system to run the program with the
following function:


14


15


Using a Switch case to construct an application form where consumers may
select

16


P5 Implement error handling and report test results.
1) Error Handling
No program or section can be considered complete unless effective error handling is
implemented. Unwanted software faults are a disaster; at most, they annoy users by
requiring them to redo minutes or hours of work, but in life-critical systems, even the
tiniest program error can result in a fatality if not handled appropriately.
If a mistake is fatal in the sense that the program cannot reasonably continue, it must
be able to "die gracefully." As a result, it must:
• tells the user why it died and.
• save as many program states as you can.
Error handling is the process of responding to and recovering from erroneous
circumstances in your program.
Java code execution may meet a number of issues, such as programming defects,
input errors, and other unanticipated events.
When an error occurs, Java normally pauses and displays an error message. The
technical phrase for this is that Java will throw an exception (throw an error). An
exception is a unique event, often a mistake, that necessitates special treatment.

Using an uninitialized reference, dividing by zero, exceeding the length of an array,
or even the JVM's inability to assign objects on the heap can all result in errors.
The try-catch block is used to implement the catch and throw exception handling
pattern. The try statement lets you to design a block of code that will be checked for
errors while it runs. If an error occurs in the try block, the catch statement allows you
to define a block of code that will be executed.
In Java, the catch block is used to manage Exceptions by defining the exception type
in the argument. The stated exception must be either an exception of the parent class
(i.e., Exception) or a produced exception type. However, it is preferable to indicate
the created kind of exception. The catch block should only be used after the try block.
With a single try block, you may utilize numerous

17


catch blocks. The terms try and catch appear in pairs:
For Example:

18


So, to capture the issue, I utilized try-catch when building the system.

Handling Error:

2) Test Result
The Results of running program tests:
Messages have to below 256

19



Results:

Test Case 1:

20


Test Case 2:

Test Case 03:

21


Test Case 04:

Test Case: A test case describes an input, action, or event, as well as the intended
response. The purpose of the test case is to determine whether or not each feature of
the software program is functioning properly.
Test Case ID

Description

1

Enter a message
here. The message
is a string of up to

250 characters. If it
has more than 250
characters, an error
warning is
displayed.

2

Check to see if a
new function has
been sent a
message.

Expected
result
Enter your
message
here. If it is
more than 250
characters, an
error notice
will show
prompting you
to input the
message
again.
Enter a
message here.
This message
has been

added to the
system.
22

Actual results

Result

String has a
length restriction
of 250
characters. Please
try again.

Pass

The message has
been added to the
system.

Pass


Tài liệu bạn tìm kiếm đã sẵn sàng tải về

Tải bản đầy đủ ngay
×