Tải bản đầy đủ (.docx) (18 trang)


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 (753.69 KB, 18 trang )

Higher Nationals in Computing


Learner’s name:
Assessor name: NGUYEN VAN SON
Learner’s ID:
Subject’s ID:
Assignment due:

Assignment submitted:


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

Student ID


Assessor name


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








❒ Summative Feedback:

❒ Resubmission


Lecturer Signature:

Assessor Signature:



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


Unit Number and Title:

Unit 19: Data Structures and Algorithms

Academic Year:


Unit Assessor:
Assignment Title:

Examine and specify ADT and DSA

Issue Date:
Submission Date:
Internal Verifier Name:

Submission 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.
● 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.
● 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:


LO1 Examine abstract data types, concrete data structures and algorithms
LO2 Specify abstract data types and algorithms in a formal notation
Assignment Brief and Guidance:
Assignment scenario
You work as in-house software developer for Softnet Development Ltd, a software body-shop providing network
provisioning solutions. Your company is part of a collaborative service provisioning development project and
your company has won the contract to design and develop a middleware solution that will interface at the frontend to multiple computer provisioning interfaces including SOAP, HTTP, JML and CLI, and the back-end
telecom provisioning network via CLI .
Your account manager has assigned you a special role that is to inform your team about designing and
implementing abstract data types. You have been asked to create a presentation for all collaborating partners on
how ADTs can be utilised to improve software design, development and testing. Further, you have been asked to
write an introductory report for distribution to all partners on how to specify abstract data types and algorithms in
a formal notation.

Part 1
You will need to prepare a presentation on how to create a design specification for data structures, explaining the
valid operations that can be carried out on the structures using the example of:
1. A stack ADT, a concrete data structure for a First In First out (FIFO) queue.
2. Two sorting algorithms.
3. Two network shortest path algorithms.
Part 2

You will need to provide a formal written report that includes the following:
1. Explanation on how to specify an abstract data type using the example of software stack.
2. Explanation of the advantages of encapsulation and information hiding when using an ADT.
3. Discussion of imperative ADTs with regard to object orientation.


Learning Outcomes and Assessment Criteria (Assignment 1)



LO1 Examine abstract data types, concrete data structures and
P1 Create a design
specification for data structures
explaining the valid operations
that can be carried out on the

M1 Illustrate, with an example, a
concrete data structure for a First
in First out (FIFO) queue.
M2 Compare the performance of
two sorting algorithms.

D1 Analyse the operation,

using illustrations, of two
network shortest path
algorithms, providing an
example of each.

P2 Determine the operations of
a memory stack and how it is
used to implement function
calls in a computer.
LO2 Specify abstract data types and algorithms in a formal notation
P3 Using an imperative
definition, specify the
abstract data type for a
software stack.

M3 Examine the advantages of
encapsulation and information
hiding when using an ADT.

D2 Discuss the view that
imperative ADTs are a basis
for object orientation and,
with justification, state
whether you agree.


Table of Contents

1. Data structures

1.1 Abstract data type
1.1.1. Definition

In computer science, an abstract data type (ADT) is a mathematical model for
data types. An abstract data type is defined by its behavior (semantics) from
the point of view of a user, of the data, specifically in terms of possible values,
possible operations on data of this type, and the behavior of these operations.


This mathematical model contrasts with data structures, which are concrete
representations of data, and are the point of view of an implementer, not a
user. (Wikipedia, 2022)

1.1.2. Common ways to represent ADT

List ADT
o The data is generally stored in key sequence in a list which has a head
structure consisting of count, pointers, and address of compare function

needed to compare the data in the list.
The data node contains the pointer to a data structure and a self-referential



pointer which points to the next node in the list.
The List ADT Functions is given below:
get () – Return an element from the list at any given position.
insert () – Insert an element at any position of the list.
remove () – Remove the first occurrence of any element from a non-empty

o remove at () – Remove the element at a specified location from a nono

empty list.
replace () – Replace an element at any position by another element.
size () – Return the number of elements in the list.
isEmpty() – Return true if the list is empty, otherwise return false.
isFull() – Return true if the list is full, otherwise return false. (Anuj Chauhan,


In this example, each element of the list in turn is stored in it and passed to
the do Something function. The loop terminates when the current position

reaches the end of the list.
Stack ADT
o In Stack ADT Implementation instead of data being stored in each node, the
pointer to data is stored.
o The program allocates memory for the data and address is passed to the

stack ADT.
The head node and the data nodes are encapsulated in the ADT. The calling


function can only see the pointer to the stack.
The stack head structure also contains a pointer to top and count of

number of entries currently in stack.
o push() – Insert an element at one end of the stack called top.
o pop() – Remove and return the element at the top of the stack, if it is not
o peek() – Return the element at the top of the stack without removing it, if
the stack is not empty. (Anuj Chauhan, 2022)
If we want to create a stack by inserting 10,45,12,16,35 and 50. Then 10
becomes the bottom-most element and 50 is the topmost element. The last
inserted element 50 is at Top of the stack as shown in the image below...

Queue ADT

o The queue abstract data type (ADT) follows the basic design of the stack
abstract data type.



Each node contains a void pointer to the data and the link pointer to the
next element in the queue. The program’s responsibility is to allocate

memory for storing the data.
o enqueue () – Insert an element at the end of the queue.
o dequeue () – Remove and return the first element of the queue if the queue
is not empty.
o peek () – Return the element of the queue without removing it if the queue

is not empty.
size () – Return the number of elements in the queue.
isEmpty () – Return true if the queue is empty, otherwise return false.
isFull () – Return true if the queue is full, otherwise return false. (Anuj
Chauhan, 2022)
Queue after inserting 25, 30, 51, 60 and 85.

1.1.3. Examples

Here are some examples of abstract data types, along with some of their operations,
grouped by kind.
• int is Java’s primitive integer type. int is immutable, so it has no mutators.
o creators: the numeric literals 0, 1, 2, …
o producers: arithmetic operators +, -, *, /
o observers: comparison operators ==, !=, <, >
o mutators: none (it’s immutable)
• List is Java’s list type. List is mutable. List is also an interface, which means that
other classes provide the actual implementation of the data type. These
classes include ArrayList and LinkedList.
o creators: ArrayList and LinkedList constructors, List.of
o producers: Collections.unmodifiableList
o observers: size, get
o mutators: add, remove, addAll, Collections.sort
• String is Java’s string type. String is immutable.
o creators: String constructors, valueOf static methods
o producers: concat, substring, toUpperCase

10 | P a g e

observers: length, charAt
mutators: none (it’s immutable)
This classification gives some useful terminology, but it’s not perfect. In complicated

data types, there may be an operation that is both a producer and a mutator, for
example. We will refer to such a method as both a producer and a mutator, but
some people would prefer to just call it a mutator, reserving the term producer only

for operations that do no mutation.
1.2 ADT usages
o The user of data type does not need to know how that data type is implemented,

for example, we have been using Primitive values like int, float, char data types only
with the knowledge that these data type can operate and be performed on without

any idea of how they are implemented.
So, a user only needs to know what a data type can do, but not how it will be
implemented. Think of ADT as a black box which hides the inner structure and
design of the data
1.2.1 Application of Stack in memory
Stack is a simple linear data structure used for storing data. Stack follows the LIFO
(Last in First Out) strategy that states that the element that is inserted last will come
out first. You can take a pile of plates kept on top of each other as a real-life example.
The plate which we put last is on the top and since we remove the plate that is at the
top, we can say that the plate that was put last comes out first.

It can be

implemented through an array or linked lists. Some of its main operations are push
(), pop (), top (), is Empty (), size (), etc. (Anuj Chauhan, 2022)
How the memory is organized
In stack-based memory management, activation records are stored in a data


structure called a stack. A stack works just like a stack of pancakes: when a

new pancake is made, it is placed on top of the stack, and when a pancake is
removed from the stack, it is the top pancake that is taken off. Thus, the last
pancake to be made is the first to be eaten, resulting in last-in, first-out (LIFO)
behavior. Activation records are similarly stored: when an activation record is
created, it is placed on top of the stack, and the first activation record to be
destroyed is the last one that was created. This gives rise to an equivalent

term stack frame for an activation record. (Anuj Chauhan, 2022)
As an example, consider the following program:

11 | P a g e

When the program is run, the main () function is called, so an activation
record is created and added to the top of the stack. Then main () calls foo (),
which places an activation record for foo () on the top of the stack. Then bar
() is called, so its activation record is put on the stack. When bar () returns, its
activation record is removed from the stack. Then foo () completes, removing
its activation record. Finally, the activation record for main () is destroyed
when the function returns. Figure 6 shows the state of the stack after each
call and return.

A stack that stores activation records.
How a method (function) calls is implemented with stack.
To make manipulations in a stack, there are certain operations provided to us. When


we want to insert an element into the stack the operation is known as the push
operation whereas when we want to remove an element from the stack the
operation is known as the pop operation. If we try to pop from an empty stack then it
is known as underflow and if we try to push an element in a stack that is already full,
then it is known as overflow. (Anuj Chauhan, 2022)

Primary Stack Operations:
o void push (int data): When this operation is performed, an element is
inserted into the stack.

12 | P a g e


int pop (): When this operation is performed, an element is removed

from the top of the stack and is returned.
Auxiliary Stack Operations:
o int top (): This operation will return the last inserted element that is at the
Qtop without removing it.
o int size (): This operation will return the size of the stack i.e., the total

number of elements present in the stack.
o int isEmpty (): This operation indicates whether the stack is empty or not.
o int isFull (): This operation indicates whether the stack is full or not.
1.3. Application of an ADT

⇒ Scenario:
Student management is always a top job of universities. With many students entering
and leaving the school, the management of student information and scores is also very
important. Along with the development of technology in general and information
technology in particular, the management of students is also increasingly modernized.
Instead of having to record books and store on traditional paper, there are now software
used to help manage students more easily. Tri An High School is a large school with a
very large number of students entering and leaving school each year, so they need a
convenient and fast student management software to replace traditional paperwork.
system. Help create convenience for teachers in managing student information and
grades. The school requires writing a program using the Java programming language to
manage students, including basic functions such as entering student lists, viewing
student lists, searching students by name. Suppose each student includes attributes like
ID, Name, Grade, semester...
Here, I would like to introduce a student management software written in Java
programming language using ArrayList data structure:
Directory structure:

Package BuildClass
o Student.java

13 | P a g e



14 | P a g e

Package UseClass
o MainClass.java

⇒ Result:

15 | P a g e

16 | P a g e

2. References

Abstract data type (2022) Wikipedia. Wikimedia Foundation. Available at: <
> (Accessed: October 6, 2022).


Abstract data types (2022) GeeksforGeeks. Available at:<
> (Accessed: October 6, 2022).


Java Stack - Javatpoint (no date) www.javatpoint.com. Available at: <
>(Accessed: October 9, 2022).

17 | P a g e