You are on page 1of 13

Higher Nationals in Computing

Unit 19: Data Structure and Algorithms


No.2

Learner’s Name: Hong Thanh Hung

Assessor Name: Le Ngoc Thanh

Class: GCS0903B

ID: GCS200345

Assignment due: June 26th, 2022

Assignment submitted: June 26th, 2022


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 Hong Thanh Hung Student ID GCS200345

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 Hung

Grading grid
P4 P5 P6 P7 M4 M5 D3 D4

2
 Summative Feedback:  Resubmission Feedback:

Grade: Assessor Signature: Date:


Internal Verifier’s Comments:

IV Signature:

1
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:

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 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
Assignment Brief 2 (RQF) ......................................................................................................2
Higher National Certificate/Diploma in Business ...............................................................2
P4 Implement a complex ADT and algorithm in an executable programming
language to solve a well-defined problem. ...............................................................5
P5 Implement error handling and report test results. .............................................7
P6 Discuss how asymptotic analysis can be used to assess the effectiveness of
an algorithm ................................................................................................................9
P7 Determine two ways in which the efficiency of an algorithm can be
measured, illustrating your answer with an example. ...........................................10
References: ...............................................................................................................11

4
P4 Implement a complex ADT and algorithm in an executable
programming language to solve a well-defined problem.
To develop data structure and algorithms I have chosen ADT array and write in the Java
language. Here is my code to implement an algorithm:
This is the App file which is take responsible to run the algorithm and give us back the
result
import java.util.Random;
public class App{
public static void main(String[] args){
Stack myStack = new Stack();
Queue myQueue = new Queue();
for (int i = 0; i < 25;i++){
String temp = "Hello ";
Random rand = new Random();
temp += rand.nextInt(100);
myQueue.enqueue(temp);
System.out.println("Messages sent from user 1: " + temp);
}
while (!myQueue.isEmpty()){
String temp = myQueue.dequeue();
myStack.push(temp);
}
System.out.println();
while (!myStack.isEmpty()){
System.out.println("Messages received from user 2: " + myStack.pop());
}
}
}

In this main function, I simulate a chatbox of user 1 and user 2. Whenever user 1 sends a
message, the message enqueue to the queue. Then user 2 saw that the program will
dequeue all of the messages in the stack to see the message.

5
This is queue, the data structure which have enqueue and dequeue function to put in and
take out the data.
public class Queue{
private int total = 0;
private String[] queue;
private int rear;
private int front;
public Queue(){
queue = new String[25];
rear = 0;
front = -1;
}
public void enqueue(String s){
if (total < 25){
total++;
front++;
queue[front] = s;
}
}
public String dequeue(){
if (total > 0){
total--;
String temp = queue[rear++];
if (rear == queue.length){
rear = 0;
front = -1;
}

6
return temp;
}
return "";
}
public boolean isEmpty(){
return total == 0;
}
public boolean isFull(){
return total == queue.length;
}
}
This is the stack, the data structure and its function have a mission that checks out the
data and stops it when it reaches the limit.
public class Stack{
private String[] stack;
private int index;
private int total = 0;

public Stack(){
stack = new String[25];
index = -1;
}
public void push(String s){
if (index < 24){
total++;
stack[++index] = s;
}
}
public String pop(){
if (index >= 0){
total--;
return stack[index--];
}
return "";
}
public boolean isEmpty(){
return total == 0;
}
public boolean isFull(){
return total == 25;
}
}

P5 Implement error handling and report test results.


Here are some test cases I have capture during doing this app
7
Test case 1 Input data Expected output Actual output Result
Show result Input data The result is clean Have some errors with Fail
the font

Test case Input data Expected output Actual output Result


Show result Input data The result is clean Not show all the result Fail

Test case Input data Expected output Actual output Result


Show result Input data The result is clean Perfect Pass

8
P6 Discuss how asymptotic analysis can be used to assess the
effectiveness of an algorithm
An algorithm's effectiveness can be determined using Big O Notation. As the input
increases, it measures the amount of time it takes to run your function. Alternatively, how
well does the function scale?
Time complexity and spatial complexity are the two components that makeup efficiency
measurement. The length of the function's computation-step execution time is known as its
time complexity. The function's utilization of memory has an impact on space complexity.
With the help of two search algorithms, this blog will demonstrate time complexity.

Illustration of Big O Notation


9
Stack illustration because it keeps items in order but only allows access to the top item, a
stack is a linear data structure similar to a list. When you hit Command + Z and Command
+ Y on a Mac or Control + Z and Control + Y on a Microsoft device to undo and redo
something, you will only be able to access the most recent modification you made in both
circumstances. When using the browser, trying to move backward or forward is another
example of a stack in action. Additionally, even though a stack is an abstract data type, it
may be implemented using actual data structures like dynamic arrays and linked lists.

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


measured, illustrating your answer with an example.
In computer science, there are typically multiple algorithms that can be used to address a
given problem. Therefore, using a method to compare the answers and determine which is
more ideal is absolutely necessary. The procedure must be:
• Independent of the computer being used to run the algorithm and its configuration.
• Displays a straight-line relationship with the number of inputs.
• Can plainly and unambiguously discriminate between two algorithms.

There are two such methods: time complexity and spatial complexity.
• Time Complexity: An algorithm's time complexity measures how long it takes to
complete a task in relation to the size of the input. It should be noted that the time
required to complete the procedure depends on the length of the input rather than
the machine's real processing speed.
The total operations for an input length on N are calculated in order to determine
the time complexity of an algorithm. It is assumed that each operation takes a fixed
amount of time, c. To comprehend the computation process, consider the following
example: Let's say that the task at hand is to determine whether a pair (X, Y) exists
in an array (A) with N elements and a sum of Z. The easiest approach is to take into
account each pair and determine whether or not it fits the requirement.

10
• Space Complexity: The amount of space an algorithm uses to operate as a function
of input length is measured by its space complexity. Here's an illustration: Imagine
you are trying to determine the frequency of an array's elements.
In addition to spatial complexity, there is auxiliary space. The primary distinction is
that although auxiliary space quantifies additional space utilized in the method
beyond the input given, space complexity quantifies the total amount of space
needed by the algorithm.

OPERATION BEST AVERAGE WORST BEST AVERAGE WORST

isEmpty() O(1) O(1) O(1) O(1) O(1) O(1)

enqueue() O(1) O(1) O(1) O(1) O(1) O(1)

dequeue() O(1) O(1) O(1) O(1) O(1) O(1)

push() O(1) O(1) O(1) O(1) O(1) O(1)

pop() O(1) O(1) O(1) O(1) O(1) O(1)

Example for Time and Space Complexity of Queue using Array

References:
Medium. 2022. Introduction to Big O Notation. [online] Available at:
<https://towardsdatascience.com/introduction-to-big-o-notation-820d2e25d3fd> [Accessed 26 June
2022].
2022. [online] Available at: <https://codenza.app/data-structures/> [Accessed 26 June 2022].
Stack, A., 2022. Array Implementation of Stack | Java Stack Implementation using Array. [online] EDUCBA.
Available at: <https://www.educba.com/array-implementation-of-stack/> [Accessed 26 June 2022].

11

You might also like