You are on page 1of 15

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 DINH HIEU Student ID GCD 18458

Class GCD0705 Assessor name HO VAN PHI

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:
Name : Lê Đình Hiếu - GCD 18458
Class : GCD 0705

Table of Contents
I. Introduction................................................................................................................................................................................. 4
II. Specification of QUEUE data structure (P1)...........................................................................................................................4
1. About the Queue..........................................................................................................................................................................4
2. Basic operations on queue data structure............................................................................................................................. 5
III. Memory stack operation and how it is used to make function calls in the computer(P2)................................................. 9
1. Stack memory in computers................................................................................................................................................. 9
2. Function calls in a computer.............................................................................................................................................. 10
For example :................................................................................................................................................................................. 11
IV. Using an imperative definition, specify the abstract data type for a software stack (P3)................................................12
1. Definition of Stack:............................................................................................................................................................ 12
2. Representing the stack data structure (Stack):................................................................................................................... 12
3. Code................................................................................................................................................................................... 13
References :....................................................................................................................................................................................15

Figure 1 : Queue data structure............................................................................................................................ 4

Figure 2 :Before and after insertion...................................................................................................................... 5

Figure 3 :Before and after retrieving data.............................................................................................................5

Figure 4 : Principle of operation stacks................................................................................................................. 9

Figure 5 : Illustrative image of a stack.................................................................................................................12


I. Introduction.

Structured Data - Structured Data is a form of data organized and classified according to a defined
structure. They are created for the purpose of storing and communicating information. The information
contained in the Structured Data will be presented in a structure identified from the outset. This is also the
reason why they are called Structured Data - Structured Data.

In computer programming, a data structure can be selected or designed to store data for the
purpose of working with it with different algorithms. Each data structure contains information about the
data values, the relationship between the data and the functions that can be applied to the data.

II. Specification of QUEUE data structure (P1).

1. About the Queue

A queue is a type of data structure of a ‘first in, first out’( FIFO) attribute. It's the same way we
humans line up to buy goods, those who queue first will be served first and leave first.

Queues are applied a lot in life, such as caching applications to save the unfinished statements to
have to execute that command after executing the previous command in sequence FIFO.

Figure 1 : Queue data structure

With Front being the first position and Rear being the end of the queue.

In the queue there are 2 main operations:

 Enqueue: Insert data at the end of the queue.


Figure 2 :Before and after insertion

 Dequeue: Get data out of the queue.

Figure 3 :Before and after retrieving data

2. Basic operations on queue data structure.

The queue data structure includes the following activities:

EnQueue: Add an item to the queue. Adding an item to the queue is always done behind the queue.

DeQueue: Removes an item from the queue. An item removed or canceled queued always from the
front of the queue.

Some other support features to help the queue work effectively:


isEmpty: Checks if the queue is empty

isFull: Check if the queue is full.

peek: Get an element in front of the queue without removing it.

Illustration :

This is an empty queue and so we have the back and the drum set to -1.

Next, I add 1 ,2 and 3 to the queue and the result looks like this:

I delete the element indicated by the forward cursor. When the front cursor is at 0, the element to be deleted is 1.
Code :
III. Memory stack operation and how it is used to make function calls in the computer(P2).

1. Stack memory in computers.

Stack memory is a special memory that is used to read information exactly in the opposite direction to
the recorded direction without regard to the organization of the data address and this is only used to store
temporary information time.

Stack memory is a sequential memory with specific access restrictions that allow it to write and read
information to / from a single location in this memory called the top of the stack. Stack memory acts as a queue
where data can be written to the top of the stack, while modifying all information stored in subsequent
locations according to a position according to the depth of the queue. this. Can only read from the stack from
the top of the stack. Reading causes the information from the top of the stack to be removed and a new
information to be written in its position from the depth of the stack with the movement of all information
stored one position to the top. of the stack. Then the queue is the last one to type first.

Stack memory is a sequential memory that only allows to write and read information coming from only
one position called the top of the stack. The memory stack acts like a queue, the data in memory changes with
the depth of the queue. The information can only be read from the top of the stack, retrieving the information
from the top of the stack changes the position of the internal data to the top of the stack. it is similar to
reloading a rifle bullet with a stack memory box, with the loading action causing the top bullet to be removed
from the cartridge and replaced at the same time as the lying bullet has been removed. after that.

Figure 4 : Principle of operation stacks.

Four instructions are used to manipulate the stack:

 Push operation
Push operation involves inserting data items into a stack. The first data item to be inserted is the most inaccessible
and located at the bottom of the stack.

 Pop activity

Pop operation involves removing data items from the stack to be loaded.

 Peek activity

In this operation, no data items are added or removed from the stack. The preview operation simply requires the
location of the data item's address at the top of the stack

 Search activity

In the search operation, no folders are added or removed from the stack. Search operation requires the address of
any folder in the stack. It locates the item relative to the item at the top of the stack.

2. Function calls in a computer.

When a function is called, a new stack frame is created

 Arguments are stored on the stack

 Current frame pointer and return address are recorded

 Memory for local variables is allocated

 Stack pointed is adjusted

When a function returns, the top stack frame is removed

 Old frame pointer and return address are recorded

 Stack pointer is adjusted

 The caller can find the return value, if there is one, on top of the stack
For example :

result :
IV. Using an imperative definition, specify the abstract data type for a software stack (P3).
1. Definition of Stack:
A stack is an abstract data structure that works on the principle of "first in first out".
A stack is a container data structure of elements and has two basic operations: push and pop. A push adds
an element to the top of the stack, that is, after the elements are already on the stack. Pop releases and returns the
element that is standing at the top of the stack. In the stack, objects can be added to the stack at any time, but only
the last added objects are allowed to be removed from the stack.

2. Representing the stack data structure (Stack):


Stack features:
The stack has a distinct characteristic that it can only be accessed at one end of it for storing and retrieving
data.
Anything added will go to the top and likewise, anything deleted will be taken from Top.
When inserting data, the stack will allow the data to be inserted from the bottom up, and vice versa
everything is deleted in the reverse order in which they were inserted.

Working with the stack includes only the following actions:


Push: Adds an element to the top of the stack, the number of items on the stack increases by 1.
Pop: Removes the first element from the top of the stack, the number of items on the stack decreases by 1.
Top: Get the value of the first element at the top of the stack, the number of items on the stack does not
change.
IsEmpty: Checks the stack is empty or not. An empty stack is a stack with no elements.
IsFull: Checks the stack is full or not. This action is not always available.

Figure 5 : Illustrative image of a stack.


3. Code
References :
https://vi.wikipedia.org/wiki/C%E1%BA%A5u_tr%C3%BAc_d%E1%BB%AF_li%E1%BB%87u

https://techtalk.vn/ngan-xep-stack-la-gi.html

https://see.stanford.edu/materials/icsppcs107/15-Function-Call-And-Return.pdf

You might also like