You are on page 1of 12

ASSIGNMENT 1 FRONT SHEET

Qualification BTEC Level 5 HND Diploma in Computing

Unit number and title Unit 19: Data Structures and Algorithms

Submission date 25/04/2021 Date Received 1st submission 25/04/2021

Re-submission Date 09/05/2021 Date Received 2nd submission 09/05/2021

Student Name Vu Tran Viet Student ID GCH190707

Class GCH0804 Assessor name Do Hong Quan

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

1
 Summative Feedback:  Resubmission Feedback:

Grade: Assessor Signature: Date:


Internal Verifier’s Comments:

IV Signature:

2
Table of Contents
Introduction .................................................................................................................................................................. 4
I. Discuss on ADT ...................................................................................................................................................... 4
Some examples of ADT are Stack, Queue, List: ........................................................................................................ 5
1. Stack .............................................................................................................................................................. 5
2. Queue............................................................................................................................................................ 5
3. List ................................................................................................................................................................. 6
II. Stack ADT .............................................................................................................................................................. 7
Stack operations ....................................................................................................................................................... 7
III. Memory Stack ................................................................................................................................................... 8
IV. Queue ADT ...................................................................................................................................................... 10
Any waiting line is a queue: ................................................................................................................................ 10
Queue operations ................................................................................................................................................... 10
V. Software Stack .................................................................................................................................................... 11
Stack ........................................................................................................................................................................ 11
Conclusion ................................................................................................................................................................... 11
References .................................................................................................................................................................. 11

Table of Figures
Figure 1: Abstract Data Type......................................................................................................................................... 4
Figure 2: Stack ............................................................................................................................................................... 5
Figure 3: Queue............................................................................................................................................................. 6
Figure 4: List .................................................................................................................................................................. 6
Figure 5: LIFO ................................................................................................................................................................ 7
Figure 6: Stack operations ............................................................................................................................................ 8
Figure 7: Stack memory ................................................................................................................................................ 8
Figure 8: Push() ............................................................................................................................................................. 9
Figure 9: Pop() ............................................................................................................................................................... 9
Figure 10: Queue......................................................................................................................................................... 10

3
Introduction
As an in-house developer for Softnet Development LTD, a body-shop software providing
corporate networking solutions. The main task is to design and implement all kinds of abstract data. This
report will present collaborating partners on how ATS is used to improve software design and
development. Besides, the report also analyzes both data types and abstract algorithms. The report will
show how to create specifications for data structures, examples of operations that can be on structures like
ADTS, QUEUE stacks, sorting algorithms…etc.

I. Discuss on ADT
Data Structures are the programmatic way of storing data so that data can be used efficiently.
Almost every enterprise application uses various types of data structures in one or the other way. This
tutorial will give you a great understanding on Data Structures needed to understand the complexity of
enterprise level applications and need of algorithms, and data structures.
The abstract datatype is special kind of datatype, whose behavior is defined by a set of values and
set of operations. The keyword “Abstract” is used as we can use these datatypes, we can perform different
operations. But how those operations are working that is totally hidden from the user. The ADT is made of
with primitive datatypes, but operation logics are hidden.

Figure 1: Abstract Data Type

4
Some examples of ADT are Stack, Queue, List:
1. Stack
• isFull(), This is used to check whether stack is full or not

• isEmpty(), This is used to check whether stack is empty or not


• push(x), This is used to push x into the stack

• pop(), This is used to delete one element from top of the stack
• peek(), This is used to get the top most element of the stack

• size(), this function is used to get number of elements present into the stack

Figure 2: Stack

2. Queue
• isFull(), This is used to check whether queue is full or not
• isEmpty(), This is used to check whether queue is empty or not
• insert(x), This is used to add x into the queue at the rear end
• Remove(), This is used to delete one element from the front end of the queue
• size(), this function is used to get number of elements present into the queue

5
Figure 3: Queue

3. List
• size(), this function is used to get number of elements present into the list
• insert(x), this function is used to insert one element into the list
• remove(x), this function is used to remove given element from the list
• get(i), this function is used to get element at position i
• replace(x, y), this function is used to replace x with y value

Figure 4: List

6
II. Stack ADT
Stack is a LIFO (Last-In, First-Out) list, a list-like structure in which elements may be inserted or
removed from only one end (last-in, first-out). Stacks are less flexible than lists, but are easier to
implement, and more efficient (for those operations they can do).

Figure 5: LIFO

Given a stack, the accessible element of the stack is called the top element.
Elements are not said to be inserted; they are pushed onto the stack.

When an element (the last one) is removed, an element is said to be popped from the stack.
Both array-based and linked stacks are fairly easy to implement. Check out the two functions
push() and pop() in the ADT of stacks & the different implementations (array-based and linked stacks)
When the user adds data to the stack, the newly added data will be at the top of the stack, similar to
removing data. For example, you add 3 numbers of 1,2,3 to the stack in order from small to large numbers,
so the first part of the stack is number 3, next, if removed, it will remove that number, then then the next
number on the top is number 2. It can be said that everything in the stack will be removed in reverse order
of the order of adding data. In order to design the stack, we often use the way for stacked and defined
stacks of them to use Array, or to use the Linked List.

Stack operations
Push: used for the purpose of inserting stack data

7
Pop: used to retrieve the data on the stack, for example when you want to get the number 5 in the
stack including numbers 1 to 10, use POP.

Peek: used when you want to identify data at the top


isEmpty: is used to determine whether the stack is empty or not.

Remove: used to delete all data in the stack.

Figure 6: Stack operations

III. Memory Stack


Stack memory is a memory usage mechanism that allows the system memory to be used as
temporary data storage that behaves as a first-in-last-out buffer. One of the essential elements of stack
memory operation is a register called the Stack Pointer. The stack pointer indicates where the current stack
memory location is, and is adjusted automatically each time a stack operation is carried out.

Figure 7: Stack memory

8
PUSH and POP are commonly used at the beginning and at the end of a function or subroutine. At
the beginning of a function, the current contents of the registers used by the calling program are stored
onto the stack memory using PUSH operations, and at the end of the function, the data on the stack
memory is restored to the registers using POP operations. Typically, each register PUSH operation should
have a corresponding register POP operation; otherwise the stack pointer will not be able to restore
registers to their original values. This can result in unpredictable behaviors, for example, function return to
incorrect addresses.
In the memory of Stack, the trigger record is at the top of the run-time stack. And when a method
is completed and finished, its trigger record will also be deleted at the top of the run-time stack, so it can
be understood more simply that the last record placed on the stack will be The first record is discarded,
and vice versa, the first record placed on the stack will be the last record removed.
Example: Invert the array

Create Stack and Push():

Figure 8: Push()

Retrieved from the Stack and put into the original array with Pop():

Figure 9: Pop()

9
IV. Queue ADT
Queue is the type of data structure in which data is arranged in the order First In / First Out. Such
as whether you are queuing up to get paid at the store, the person who is in the front will be paid first. Is a
structure where data can be used at both ends. Developed by adding data to the end and recording by
taking elements from its front.
A queue is a FIFO (first in, first out) data structure.

Any waiting line is a queue:


• The check-out line at a grocery store
• The cars at a stop light
• An assembly line
Unlike the stack, Queue has 2 open doors, one to add input and one to serve the deletion of data,
such as adding data including 3 numbers of 1,2,3 in order from small numbers to such a large number, the
next added data will be behind the number 3, the deleted number will be 1

Queue operations
The following operations are used in queues to manage queues.

• First: Examines the element at the front of the queue


• isEmpty: Examines the element at the front of the queue
• enqueue: Adds an element to the rear of the queue
• dequeue: Removes an element from the front of the queue
• size Determines the number of elements in the queue
• toString Returns a string representation of the queue

Figure 10: Queue

Uses of Queues in Computing:

• For any kind of problem involving FIFO data


• Printer queue (e.g. printer in MC 235)

10
• Keyboard input buffer
• GUI event queue (click on buttons, menu items)
• To encode messages (more on this later)

V. Software Stack
A software stack is a group of programs that work in tandem to produce a result or achieve a
common goal. Software stack also refers to any set of applications that works in a specific and defined
order toward a common goal, or any group of utilities or routine applications that work as a set. Installable
files, software definitions of products and patches can be included in a software stack. One of popular
Linux-based software stack is LAMP (Linux, Apache, MYSQL, Perl or PHP or Python) .WINS (Windows
Server, Internet Explorer, .NET, SQL Server) is a popular Windows-based software stack.
Stack
Stack(S): max_capacity;

Operation Pre-condition Post-condition Erro-condition


isEmpty(): boolean None Size(S) == 0 None

isFull(): boolean None Size(S) == max_capacity None


Push(int i): boolean isFull(S) == False Top(S) == i isFull(S) == True
Stack Overflow
Pop(): Integer x isEmpty(S) == False Size(S) == n-1 isEmpty(S) == True
size(S) > 0 x == a Stack Underflow
a = top(S)
Peek(): Integer x isEmpty(S) == False x == a isEmpty(S) == True
size(S) > 0 Stack Underflow
a = top(S)

Conclusion
In this report, define Abstract Data Type, the definition and understanding of Stack, Queue has
been presented, the report has indicated about their activities, given examples, applications and
explanation on how to specify an abstract data type using the example of software stack.

References
Chakraborty, A., 27-Aug-2019. Abstract Dât Type in Dât Structures. s.l.:s.n.

Humby, M., 2015. Abstract data type. s.l.:s.n.

Ramgir, M., 2017. Java 9 High Pẻomance. s.l.:s.n.

11
12

You might also like