You are on page 1of 18

Data Structures

Name: Nguyen Anh Khoa


Class: GCS0903B Mentor: Le Ngoc Thanh
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 Anh Khoa Student ID GCS190627

Class GCS0903B Assessor name Le Ngoc Thanh

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
 Summative Feedback:  Resubmission Feedback:

Grade: Assessor Signature: Date:

Internal Verifier’s Comments:

IV Signature:
Assignment Brief 2 (RQF)
Higher National Certificate/Diploma in Business

Student Name/ID Number:

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:

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 http://cms.greenwich.edu.vn/.
● Remember to convert the word file into PDF file before the submission on CMS.

Note:

● 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.
Learning Outcomes and Assessment Criteria (Assignment 2)

Pass Merit Distinction

LO3 Implement complex data structures and algorithms

P4 Implement a complex ADT M4 Demonstrate how the


D3 Critically evaluate the
and algorithm in an executable implementation of an complexity of an
programming language to solve ADT/algorithm solves a well- implemented
a well defined problem. defined problem ADT/algorithm

P5 Implement error handling


and report test results.

LO4 Assess the effectiveness of data structures and algorithms

P6 Discuss how asymptotic M5 Interpret what a trade-off is D4 Evaluate three benefits of


analysis can be used to assess when specifying an ADT using using implementation
the effectiveness of an an example to support your independent data structures
algorithm answer
P7 Determine two ways in
which the efficiency of an
algorithm can be measured,
illustrating your answer with
an example.
Contents
I. Implement a complex ADT and algorithm in an executable
programming language to solve a well defined problem ...................... 8
1. Requirement of program ................................................................ 8
Message transfer program: .............................................................. 8
This programming include: ............................................................... 8
2. Implement program in java ........................................................... 8
3. Error handling and report test results .......................................... 13
Error handling ................................................................................. 13
Test results ...................................................................................... 13
4. How the implementation of an ADT/algorithm solves a well-
defined problem ................................................................................ 16
Using Queue ADT ............................................................................ 17
Using Stack ADT .............................................................................. 17
5. Evaluation the complexity of an implemented ADT/Algorithm .. 17
REFERENCE ......................................................................................... 18
I. Implement a complex ADT and algorithm in an
executable programming language to solve a well
defined problem
1. Requirement of program
Message transfer program:
The system should be designed 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.

This programming include:


- Using ADT STACK / Queue) as a buffer during data transmission and reception
- Error handling: use the Exception catcher - the "try ... catch" block to catch and handle errors if
any arise during program execution
- Test program and report test results (Test case, test log)

2. Implement program in java


• Class Node: used to declare variables
• Class MyQueue:
• Class MyStack:
• Class main
3. Error handling and report test results
Error handling
An exception is a problem that arises during the execution of a program. A java exception is a
response to an exceptional circumstance that arises while a program is running.
Exceptions provide a way to transfer control from one part of a program to another. java
exception handling is built upon four keywords: try, catch, finally, and throw:
- Try: A try block identifies a block of code for which particular exceptions is activated. It is
followed by one or more catch blocks.

- Catch: A program catches an exception with an exception handler at the place in a


program where you want to handle the problem. The catch keyword indicates the
catching of an exception.

- Finally: The finally block is used to execute a given set of statements, whether an
exception is thrown or not thrown. For example, if you open a file, it must be closed
whether an exception is raised or not.

- Throw: A program throws an exception when a problem shows up. This is done using a
throw keyword.

Test results
Results of running program tests:
Check new function is sent message
Check the feature of receiving messages

Check the feature of displaying all messages


Test case: Test case is describing an input, action or an event and an expected response. Test
case is to check whether each function of the software application is working properly or not.
Test case ID Description Expected result Actual results Result
1 Enter a message. Enter your The length limit Fail
The message is a message. If it of string is 250.
string of maximum exceeds 250 Please again.
250 characters. If it characters, an
exceeds 250 error message will
characters, an error appear asking you
message is output. to enter the
message
2 Check new function Enter a Message has added Pass
is sent message message. This to system.
message has
added to
system.
3 Check the feature The system will The system Pass
of receiving receive the received the sent
messages sent message message
4 Check the feature Display all All messages have Pass
of displaying all messages in been displayed in
messages the system the system
4. How the implementation of an ADT/algorithm solves a
well-defined problem
The system is using Queue as a buffer and Stack to get data to Destination Message. There are a
Transfer Function will do that. To visualize the algorithm I will show you how system work with
Flow Chart below:
Using Queue ADT
In this system, I have used 3 function in Queue to make a Buffer such as: Enum(), Enqueue() and
Dequeue():
- Enum() function: Check how many element in Queue (Buffer). So we can set a maximum
character in Buffer.
- Enqueue() function: This function allow to insert the character into Queue (Buffer) and
this function is only execute when the value from Enum() is bigger than 0. It means
Enqueue() just work when the Queue (Buffer) is not Full.
- Dequeue() function: This function return the first character of the Queue (Buffer). This
function is only execute when the value from Enum() is different with 0 and after the
Queue (Buffer) is Full. Dequeue() will stop when the Queue (Buffer) is empty.

Using Stack ADT


In this system, I have used 2 function in Stack to make a Destination Message such as:
Push() and Pop():
- Push() function: Insert the character into the top position of stack. In this program,
I’m using Push() with value: Dequeue() in Queue (Buffer). So the Stack can get
character from Queue (Buffer). Push() function will stop when the Queue (Buffer) is
empty.
- Pop() function: This function will return the top character in Stack and stop when the
Stack is empty. After that I connect each character into string (Destination Message)
with this equation: Destination = Pop() + Destination

5. Evaluation the complexity of an implemented


ADT/Algorithm
In order to achieve an efficient Queue implementation, where Queue and Stack operations
have the perfect time complexity O(1). But in the Transfer function we have complexity of
algorithm is O(n^2) so when we run this program, the complexity is also know as O(n^2).
As a result we can see that the time of algorithm increase same as an algorithm's complexity:
REFERENCE

geeksforgeeks, n.d. geeksforgeeks. [Online]Available at:


https://www.geeksforgeeks.org/analysis-of-algorithms-set-1-asymptotic-analysis/
purplechaiblogger, n.d. purplechaiblogger. [Online]Available at:
http://www.purplechaiblogger.com/data-structure-importance-and-advantages/ tutorialspoint,
n.d. tutorialspoint. [Online]Available at:
https://www.tutorialspoint.com/data_structures_algorithms/asymptotic_analysis.htm
wikipedia, n.d. wikipedia. [Online]Available at:
https://en.wikipedia.org/wiki/Asymptotic_analysis wikipedia, n.d. wikipedia. [Online]Available
at: https://en.wikipedia.org/wiki/Big_O_notation

You might also like