Professional Documents
Culture Documents
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.
Student’s signature
Grading grid
P1 P2 P3 M1 M2 M3 D1 D2
Summative Feedback: Resubmission Feedback:
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
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.
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.
With Front being the first position and Rear being the end of the queue.
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.
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).
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.
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.
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.
https://techtalk.vn/ngan-xep-stack-la-gi.html
https://see.stanford.edu/materials/icsppcs107/15-Function-Call-And-Return.pdf