Asm2 Java Programming
Asm2 Java Programming
ASM2-Java Programming
Class: GCS0903B
ID: GCS200345
Unit number and title Unit 19: Data Structures and Algorithms
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.
Grading grid
P4 P5 P6 P7 M4 M5 D3 D4
IV Signature:
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.
Assignment scenario
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
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.
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;
}
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;
}
}
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.
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
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