You are on page 1of 26

ASSIGNMENT 1 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 Le Nguyen Duc Duy Student ID GCD201871

Class GCD0905 Assessor name Pham Thanh Son

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:
TABLE OF CONTENTS

I. Introduction______________________________________________________________________________4
1. Scenario_________________________________________________________________________________4
2. Report___________________________________________________________________________________4
II. Data structures:__________________________________________________________________________5
1. Data structures____________________________________________________________________________5
2. Abstract data types_________________________________________________________________________5
a. Definition :_______________________________________________________________________________5
b. Example of ADT__________________________________________________________________________7
III. ADT usages___________________________________________________________________________11
1. Application of Stack in memory_____________________________________________________________11
2. Application of an ADT:____________________________________________________________________19
IV. Conclusion____________________________________________________________________________23
TABLE OF FIGURES

Figures 1. Abstract Data Type......................................................................................................................................6


Figures 2. Singly-linked lists........................................................................................................................................7
Figures 3. SinglyLinkedList code 1..............................................................................................................................8
Figures 4. SinglyLinkedList code 2..............................................................................................................................8
Figures 5. SinglyLinkedList code 3..............................................................................................................................9
Figures 6. SinglyLinkedList code 4..............................................................................................................................9
Figures 7. SinglyLinkedList.......................................................................................................................................10
Figures 8. Illustration addFirst....................................................................................................................................10
Figures 9. Illustration removeFirst.............................................................................................................................11
Figures 10. SinglyLinkedList Result..........................................................................................................................11
Figures 11. Stack memory..........................................................................................................................................12
Figures 12. Illustration (1)..........................................................................................................................................13
Figures 13. Illustration (2)..........................................................................................................................................13
Figures 14. Illustration (3)..........................................................................................................................................14
Figures 15. Illustration (4)..........................................................................................................................................14
Figures 16. Illustration (5)..........................................................................................................................................15
Figures 17. Illustration (6)..........................................................................................................................................15
Figures 18. Example Function call.............................................................................................................................16
Figures 19. Illustration Function call..........................................................................................................................16
Figures 20. Result of Illlustration...............................................................................................................................16
Figures 21. Stack (1)...................................................................................................................................................18
Figures 22. Stack(2)....................................................................................................................................................18
Figures 23. Stack(3)....................................................................................................................................................18
Figures 24. Main Stack...............................................................................................................................................19
Figures 25. Result.......................................................................................................................................................19
Figures 26. Student (1)...............................................................................................................................................20
Figures 27. Student (2)...............................................................................................................................................20
Figures 28. GreatStudent............................................................................................................................................21
Figures 29. Array(1)...................................................................................................................................................22
Figures 30. Array(2)...................................................................................................................................................22
Figures 31. Array(3)...................................................................................................................................................23
Figures 32. Array(4)...................................................................................................................................................23
Figures 33. Main Array...............................................................................................................................................23
Figures 34. Result.......................................................................................................................................................23

I. Introduction
1. Scenario
 As part of a service delivery partnership project, SoftNet Development Ltd, a software firm that supplies
networking solutions, has hired my company to create and install a middleware solution that would front
end with a number of interfaces. The computer delivery interface can be used to communicate with the
back-end telecommunications service network using CLI, in addition to SOAP, HTTP, JML, and other
protocols.
 My account manager has entrusted me with the special duty of educating my team on the development and
application of abstract data types. I was asked to give a presentation to all of the working partners on how
to use ADT to improve software design, development, and testing. All partners needed to receive the formal
specification of abstract data types and techniques, so I also had to write an introduction report.

2. Report
 I'll demonstrate how to write a design specification for a data structure and how to enumerate the legal
operations that may be carried out on the structure.
 How are abstract data types supposed to be defined?
 What advantages information encapsulation and hiding have when used with ADT?
 What ADTs are necessary for object orientation?

II. Data structures:


1. Data structures
 Computers handle enormous amounts of data to provide relevant and practical facts. In order for computers
to process the information as rapidly as possible, data must be stored in a way that takes the least amount of
memory while yet allowing for efficient access. Although computers have enough of memory and
processing capacity to store a lot of data, the system won't function properly if software systems are
developed using the incorrect data structures.
 Data is stored and organized using data structures. It provides a mechanism to quickly access and update
computer data. In accordance with the objectives of your project, you should choose the best data format.
Data is gradually stored in memory via arrays.
 The ability to read, modify, and subject data bits to various processes is made possible by the storing of
data in data structures. Operations on data structures must be carried out using the right algorithms because
computers handle the majority of data organization. Data structures' main objective is to minimize the time
and space needed for various operations.

2. Abstract data types


a. Definition :
 An object's behavior may be represented as a set of values and a series of actions; this behavior is known as
an abstract data type (ADT). ADT is simply described in terms of the actions that must be taken, not in
terms of the procedures that must be followed. It is uncertain how the procedures will be carried out and
how the data will be stored in memory. Because it provides a perspective that is independent of
implementation, it is referred to be "abstract."
Figures 1. Abstract Data Type
 An abstract data type (ADT) is a collection of clearly specified data values and related actions that are
independent of the technology used to create them. Consequently, an abstract data type is a collection of
methods used to handle a well-organized set of data. The collection of operations defines the ADT's
interface. As long as the ADT complies with the criteria of the interface, how it is implemented actually
doesn't matter. Since ADT data values and operations are described mathematically rather than in a
computer language, we may reason about the outcomes of operations, relationships with other abstract data
types, whether the program implements the data type, etc.
 We are able to hide the data representation behind interfaces thanks to abstract datatypes. We still require a
sizable class of concrete datatypes with non-hidden representations in order to transmit data across
interfaces. This is especially important when using a network for communication. In this case, passing a
reference to an abstract object would be wasteful; instead, we should explicitly specify the object's contents.
 Features of ADT:
 Abstraction: It is not necessary for the user to comprehend how the data structure is put into use.
 Better Conceptualization: ADT has helped us better comprehend the real world.
 The program is accurate and able to spot mistakes.
 An abstract user-defined data type provides:
 The representation of these variables is concealed, although program units can define variables of a
type using a type specification.
 A selection of methods for dealing with goods of this nature.
b. Example of ADT
An implementation of such an interface that offers code for the internal functions is a data structure. Real-world
implementations of operations like Arrays, Singly, Doubly, and Circular Linked Lists are provided by concrete
data types. Array-List, Stack, and Queue ADTs are only a few examples of abstract data types that may be
constructed using concrete data types as their building pieces. I'll use the ArrayList class to describe a few basic
ADT instances below.

 Singly Linked Lists:

Figures 1. Singly-linked lists

 Single-linked list is one of the most fundamental data structures you will learn in this course. A
value and, if any, a reference to the node that comes after it in the list make up each node in this
singly linked list.
 It is the most basic kind of linked list in which each node contains a pointer to the node immediately
following it, which also contains some data of the same type.
 When a node claims to have a reference to the node following it in the sequence, it actually
indicates that it retains the address of that node. Data can only be traversed once in a single linked
list. The similar image is shown below.
 Representation of Singly-linked Lists:
A pointer to the list's first node serves as the representation of a linked list. The linked list's
head is represented by the first node. The value of the head points to NULL if the linked list
is empty.
 An indication (store with integers, strings, or any type of data).
 a node address or a reference (or pointer) to the node after that (which joins one node
to another).
 Implement SinglyLinkedList in Java:
Figures 2. SinglyLinkedList code 1

Figures 3. SinglyLinkedList code 2


Figures 4. SinglyLinkedList code 3

Figures 5. SinglyLinkedList code 4


 Explan SinglyLinkedList: Make a class named Node using the variable's data as the basis. Make it longer
by adding a node at the beginning; I do this by making addFirst(E element) add an element before the list.
Create addLast(E element) and add an element after the collection's final element to raise the collection's
size. Simply instructing the list to disregard the first button and utilize the next will get rid of the initial
position. Create the function E removeFirst to eliminate and return the collection's first entry (). If this is
not the case, throw an IllegalStateException with the necessary message. Create the expression E
removeLast (), which, if it exists, removes and returns the collection's last element. If not, an
IllegalStateException with the necessary message is thrown. One must first create a temporary variable
called current before one can delete at the end. The temporary variable must then be created, given the tail
value, and allowed to run all the way to the end of the list before being stopped. The nodes must then be
ignored until the list is finished before the list's size is reduced. Before using the toString() function to show
the list, the ensureNonEmpty() method checks to see whether the list isn't empty. If yes, E getFirst() returns
the first element of the list without removing it; if not, it produces an IllegalStateException with the
appropriate message. If there is just one element left in the list, E getLast() returns it; otherwise, it generates
an IllegalStateException with the appropriate message. Use the int size() method to get the list's element
count back. The boolean isEmpty() method checks to see if the list is empty.
 Result SinglyLinkedList:

Figures 6. SinglyLinkedList

Figures 7. Illustration addFirst


Figures 8. Illustration removeFirst

Figures 9. SinglyLinkedList Result

Explan code: when I use method addFirst(), number will add to mySinglyLinkedList and the next I use method
addLast() to add number behind the list and display them. I use removeLast to remove number the last in list but
before remove, I setting method to display number on screen before delete and I call list of number again to show
the list after delete number.

III. ADT usages


1. Application of Stack in memory
The last-in, first-out (LIFO) concept can be used with a stack to insert and remove data. As a result, memory
operations are handled in a certain manner. A fresh element that has been added to the stack always climbs to the
top. The most recent item is removed first when elements are removed from stacks, which is known as the LIFO
characteristic. This looks like a line of stacked saucers or tiles. The saucers are piled high, and when we remove
them, we start with the most recent addition.
System memory can be employed as a first-in, last-out buffer for short-term data storage, a memory management
strategy known as stack memory. The register known as the Stack Pointer is one of the crucial components of stack
memory operation. After every stack action, the stack pointer, which displays the position of the current stack
memory address, is automatically updated.

Adding data to the stack with the PUSH instruction is known as pushing, and removing data from the stack is
known as popping. Depending on the CPU architecture, some processors use incremental address indexing while
others use decrement address indexing when adding new data to stack memory. The stack operation in Cortex-M
processors is built on the "full-descending" stack concept. As a result, the stack pointer shrinks with each new data
storage and always links to the stack memory's most recently filled data.

PUSH and POP are frequently used at the start and end, respectively, of a function or subroutine. The caller
program's current register values are first momentarily stored on the stack memory using PUSH operations. The
data in the stack memory is then returned to the registers at the function's conclusion using POP operations. The
stack pointer won't be able to reset registers to their default values if there isn't a register POP action for each
register PUSH operation. This could result in unexpected behavior because the function might return to the wrong
addresses.

Figures 1. Stack memory

 Features of Stack:

Some of the features:

 A stack is an ordered collection of objects of a same type. an array used to hold strings or integers, for
instance.
 The basis of this system is FILO (First-In-Last-Out) or LIFO (Last-In-First-Out) features.
 When a stack is entirely full, it is said to be in the overflow state, and when it is entirely empty, it is said
to be in the underflow state.
 How to Stack in DataStructure ?

A stack is a very simple data structure that can only perform the two operations Push and Pop. These actions help
explain how the stack functions as a data structure. As they are each individually detailed below, let's look at them
one at a time. Let's look at the insertion and deletion (removal) operations in a stack that are covered below.

 Insertion Operation

When an element is added to a data structure, a push operation occurs. As an object is pushed into a pit, an element
that is added to a stack falls to the bottom. Each ingredient is added one after the other, with the next one coming
after the previous one. Every time an insertion operation—also referred to as a "posh operation"—takes place, one
element is placed into the stack. We shall understand how push operations work by the actions that follow.

Think about the following five figures: 39, 38, 2022, and 4. To store these pieces in memory, we'll employ a stack
data structure. The parts have to be stacked in that particular sequence. The push operation will proceed in this case
as detailed below.

At first, as seen in the illustration below, the stack is empty. The push operation will be used to add each element to
this stack.

Figures 2. Illustration (1)

 The second, I add 39 initially inserted into the stack using the push operation, taking up the bottommost
position.

Figures 3. Illustration (2)

 Lastly, The push() operation is used to add element 38, 2022, 4, as shown below, as the following element
to be added to the stack. The stack then becomes full after the last element is added. This is depicted as
follows.
Figures 4. Illustration (3)

 Operations for deletion or removal

We shall understand the deletion operation in the stack by using the illustration from the insertion operation
section. starting with the last deed in the prior section We are aware of this now that the stack is full. The stack's
elements will all be removed at once. Taking an element out of the stack is done by the "Pop" action. The first step
of the pop operation is to remove the most recent element to be added. The removal action in the stack will
function as described below and will be enabled by the pop operation.

 The stack is full. As shown in the following,


 Firstly, the item in the stack that is at the top is number 4. It is the newest addition to the stack of
components. The pop procedure initially removes this element. It is shown as follows.

Figures 5. Illustration (4)


 Continues, I pop 2022, 38 out of stack. As a result, the pop operation removes each stack element
separately. There are now 39 items left in the stack. Element 39, as we all know, was the first element
to be added to the stack, but when it came time to remove it, it actually became the final element to do
so since we must first delete the element that is above it in order to remove it. As a result, the stack's
insertion and deletion operations adhere to the LIFO (Last-In-First-Out) principle. As indicated below,
the final component is eliminated.
Figures 6. Illustration (5)
 The stack will empty while I pop the last element in the stack:

Figures 7. Illustration (6)


 The Top operation in the stack returns the topmost element in the stack, as the name implies. Similar to
this, the Search operation allows you to search the data structure.
 Applications of Stack in Data Structure
 The stack is the data structure that reverses a string the simplest. This is made simpler by the stack's
Last-In, First-Out (LIFO) architecture.
 The stack is a particularly effective data structure for parsing tasks.
 It is also used to change expressions, such as changing an expression from a postfix to an infix or vice
versa.
 It is highly efficient when it comes to backtracking.
 Pros of Stack Memory:
 Last In First Out (LIFO) data management is not feasible with a linked list or array.
 Local variables are automatically freed from the stack once a function returns, and the stack is created
when a function is invoked.
 A stack is utilized when a variable is not used outside of that function.
 It enables you to control memory deallocation and allocation.
 Stacking automatically cleans up the thing.
 It holds up well to corruption.
 Variables' sizes cannot be modified after they have been stated.
 Cons of Stack Memory:
 There is a serious paucity of stack memory.
 Random access is not practical.
 If there are an excessive number of newly formed items on the stack, stack overflows may happen more
frequently.
 Functions or programs may behave in an undefinable fashion as a result of overwriting variables.
 An unexpected termination could occur as the stack leaves the memory area.

An example, following program:

Figures 8. Example Function call

Figures 9. Illustration Function call

Figures 10. Result of Illlustration


When the program runs, the main() function is invoked, which results in the creation and addition of an activation
record to the top of the stack. As a result, when main() calls hello, the trigger record is put at the top of the stack ().
After greeting() is called, the trigger record is then put on the stack. When it returns, the Greeting(trigger) record is
dropped from the stack. Hello() terminates with the deletion of its activation record. lastly, the trigger record for
main() is removed after the procedure returns.

 Function call in a computer?

A function is a section of code that may be invoked anytime a certain job has to be performed. To properly employ
numerous function calls or recursion and to better understand the code, it is necessary to appreciate the concept of
a function call. Understanding how function calls operate requires some prior knowledge of CPU program
execution, program stacks, and stack frames (Activation Record).

 Program Stack: The main functions are the items at the bottom of the program stack, which is made up of
all function calls.
 Stack Frame: The data from the called function is contained in a "Stack Frame," a component of the
program stack. Some of that is :
 Return Address
 Input Parameter
 Local Variables
 Register Savings
 Stack pointer: The stack Pointer, which is a pointer to the top of the program stack, indicates the most
recent function that was called.

The freshly constructed stack frame that is pushed into the program stack each time a function is called has
replaced the stack pointer, which previously always pointed to the top of the program stack. The data for the called
function is all contained in this stack frame.

Action occur when I call the function :

 The stack is pushed up against the frame.


 Subroutines' instructions are executed.
 The stack's frame is popped.
 Program Counter is currently keeping the return address.

The POP instruction in assembly language removes the top of the stack and assigns it to the program counter.

 How to Function Calls work with stack?


Figures 11. Stack (1)

Figures 12. Stack(2)

Figures 13. Stack(3)


Figures 14. Main Stack
Explan code: I push number into myIntergerStack, the number I push will stay bottom in the stack the last number
I push will on the top. I use pop() method to remove number but in this method, I call data to show number I will
remove to make sure this code don’t have any problem, and the result I get is :

Figures 15. Result


2. Application of an ADT:
To describe a list of student of a university with basic information like ID, name, age,score and giaiDacBiet, I will
use an ADT as Array. It is simple to handle tasks like printing a list of all greatstudent, printing an student's details
at a specific index, and deleting an student at a specific index. I believe that using an array is the best solution to
this issue.
Figures 1. Student (1)

Figures 2. Student (2)


Figures 3. GreatStudent
Figures 4. Array(1)

Figures 5. Array(2)
Figures 6. Array(3)

Figures 7. Array(4)

Figures 8. Main Array

Figures 9. Result
IV. Conclusion
In this report, I covered abstract data types, how to build data structure design specifications, and a sample that
explains the legitimate operations that may be done with the structure's data that is set aside for the First In First
Out (FIFO) queue. This paper has been revised to discuss the advantages of information hiding and encapsulation
when utilizing ADTs as well as the ADTs required for object orientation. In addition, this study serves as the basis
for my next report.

References
Anon., 2012. What is ADT? (Abstract Data Type). [Online]
Available at: https://stackoverflow.com/questions/10267084/what-is-adt-abstract-data-type
[Accessed 5 12 2022].

Anon., n.d. Abstract Data Type (ADT). [Online]


Available at: https://dotnettutorials.net/lesson/abstract-data-type/
[Accessed 5 12 2022].

Chauhan, A., 2022. Geeksforgeeks. [Online]

Available at: https://www.geeksforgeeks.org/abstract-data-types/


[Accessed 8 12 2022].

Chumbley, A., 2022. Brilliant. [Online]

Available at: https://brilliant.org/wiki/shortest-path-algorithms/


[Accessed 11 12 2022].

Deepali, 2022. Naukri. [Online]

Available at: https://www.naukri.com/learning/articles/queue-data-structure-types-implementation-


applications/
[Accessed 11 12 2022].

Differences, T., 2022. Tech Differences. [Online]

Available at: https://techdifferences.com/difference-between-bubble-sort-and-selection-


sort.html#:~:text=Bubble%20sort%20takes%20an%20order%20of%20n%20time,bubble%20sort%20whic h%20is
%20very%20slow%20and%20inefficient.
[Accessed 11 12 2022].

Fisher, C., 2021. Medium. [Online]

Available at: https://medium.com/dvt-engineering/data-structures-part-1-concrete-data-types-


d30a8b36efe2
[Accessed 8 12 2022].
freecodecamp, 2019. freecodecamp. [Online]

Available at: https://www.freecodecamp.org/news/sorting-algorithms-explained-with-examples-in-


python-java-and-c/
Accessed 12 12 2022].

GeeksforGeeks, 2022. Ankit Bisht. [Online]

Available at: https://www.geeksforgeeks.org/stack-vs-heap-memory-allocation/


[Accessed 09 12 2022].
Ginni, 2021. Tutorialspoint. [Online]

Available at: https://www.tutorialspoint.com/what-is-memory-stack-in-computer-


architecture [Accessed 12 2022].

Huawei, 2022. Huawei. [Online]

Available at: https://forum.huawei.com/enterprise/en/data-structure-types-1/thread/


889401-891 [Accessed 08 12 2022].

Kamil, A., 2019. eecs280staff. [Online]

Available at: https://eecs280staff.github.io/notes/02_ProceduralAbstraction_Testing.html


[Accessed 10 12 2022].

You might also like