












Preview text:
UNIVERSITY OF TECHNOLOGY AND EDUCATION
FACULTY OF INTERNATIONAL EDUCATION HCMUTE DATA STRUCTURES AND ALGORITHMS FINAL TEAM PROJECT STACK COURSE CODE: DASA230179E
Lecturer: Ths.Trương Thị Ngọc Phượng Student ID Name Contribution (%) 24110109 Huỳnh Thuyền Nam 100% 24110126 Phạm Nguyễn Vương Quốc 100% 24110072 Hà Duy Anh 100%
Ho Chi Minh City, January 15, 2026 Table of Contents Introduction 2 1 Stack 3 1.1
Definition . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3 1.2
The Stack Abstract Data Type (ADT) . . . . . . . . . . . . . . . . . . . . . . . 4 1.3
Stack Interface Using HTML, CSS, and JavaScript
. . . . . . . . . . . . . . . . 6 2
Advantages and Disadvantages of Stack 9 3 Applications of Stack 10 Conclusion 11 References 12 Introduction
In the field of computer science, data structures play an important role in organizing and
managing data effectively. Each type of data structure has its own characteristics and different
advantages, serving many different purposes. Among them, the stack is one of the most basic
and most common data structures.
A stack operates according to the LIFO model or “last in - first out”. This means
the last element inserted is also the first element removed. Thanks to its simple operating
mechanism, the stack becomes the foundation for many algorithms and programming tasks
such as expression processing, recursive function calls, and more.
This report will study the stack in order to better understand its structure, operating
method, and implementation in a web environment. From there, we can better understand its
operating principles as well as the real-life applications of the stack. 1 Stack 1.1 Definition
A stack is a linear data structure in which data elements are arranged in sequence, one
element after another. A stack can be viewed as a pile of plates. When adding a new plate on
top of the pile, this is the operation of adding an element (push) into the stack. Conversely,
when taking out a plate to use, the plate on the top will be taken out first. This corresponds
to the operation of removing or deleting an element (pop) from the stack. Therefore, a stack
is called a LIFO (Last In - First Out) or FILO (First In - Last Out) list.
LIFO (Last In - First Out) or FILO (Last In - First Out) is the core operating principle
of a stack. LIFO means the element added last will be the first one removed. When adding
a new element (push), that element becomes the new top. When removing an element (pop),
that same element is removed and the element below it (if any) becomes the new top. 1.2
The Stack Abstract Data Type (ADT)
The stack is an abstract data type widely used because it is easy to use, but also very
important because it has many applications. The Stack Abstract Data Type (ADT) describes
a stack as a collection of objects and operations, where all operations are performed at one end
called the “top”, without needing to care about how it is implemented internally. The basic
operations for a data structure to be called a stack include:
Push: Adds a new element to the stack. The new element becomes the new top of the
stack and the size of the stack increases by one after each valid push operation.
• Pseudocode for method Push(value) x ← random(0, 999) top ← top + 1 stack[top] ← x
Pop: Removes or deletes an element from the stack. When performing Pop(), the top
element is taken out and removed from the stack. At the same time, the element below it
(if any) becomes the new top and the size of the stack decreases by one for each successful pop.
• Pseudocode for method Pop() if top = -1: return null x ← stack[top] top ← top - 1 return x
Peek/Top: Views the top element of the stack. This operation returns the top element
of the stack while keeping all elements unchanged.
• Pseudocode for method Peek/Top() if top = -1: return null return stack[top]
. In addition, there are supporting operations to make working with a stack more convenient:
• IsEmpty(): Checks whether the stack is empty. Returns true if the stack is empty, false
otherwise. This is used to avoid Stack Underflow errors.
• IsFull(): Checks whether the stack is full. Returns true if the stack is full, false if there
is still space. This operation is commonly used for stacks implemented with fixed-size
arrays to avoid Stack Overflow errors.
• Size(): Returns the size of the stack.
When working with stacks, there are two common errors:
• Overflow: Occurs when pushing into a full stack.
• Underflow: Occurs when popping from an empty stack. 1.3
Stack Interface Using HTML, CSS, and JavaScript
During the process of learning data structures and algorithms, if we only focus on theory
to understand how a stack works, it can become too abstract. To form that abstraction through
visualization, our team developed a stack simulation interface on a web platform so that users
can easily observe and perform basic functions related to this data structure. The interface helps
improve learning and understanding by displaying key operations such as adding, removing,
and viewing the top element of the stack.
Figure 1: Stack interface on the web
Functions of Each Component in the Interface
• Input Value: Allows the user to freely enter the value they want to push into the stack.
This value will be used when performing the Push operation.
• Push: Adds a new value to the top of the stack. The value is taken from the Input
Value box or can be randomly generated using the Random button.
• Pop: Removes the element currently at the top of the stack, demonstrating the LIFO
(Last In First Out) principle of stack operation.
• Peek: Displays the value of the element at the top of the stack without removing it from
the stack. This element is highlighted in yellow when clicked, making it easier for users to observe and understand.
• Random: Automatically generates a random value and pushes it directly into the stack.
• Reset: Removes all elements from the stack and returns it to its initial state.
• Function Code: A small box that displays the code of the above functions to help us
better understand how the algorithm works. 2
Advantages and Disadvantages of Stack Advantages
• The stack is relatively easy to implement and can be simply built using an array or a linked
list. The basic operations of a stack are clear, easy to understand, and easy to perform.
Thanks to the LIFO mechanism, the stack enables fast access time for operations.
• Since elements are stored in contiguous memory areas, it improves access efficiency and
reduces processing cost. The stack also plays an important role in managing function
calls and execution states, especially in programs that use recursion.
• The stack is also widely applied in compiler design. In addition, stacks are the foundation
for undo and redo features in many applications such as word processors, design tools, and more. Disadvantages
• The capacity of a stack is limited, especially when implemented using a fixed-size array.
When the stack is full, adding a new element may cause a stack overflow error, leading to interruption or data loss.
• It does not support random access to elements in the stack. Users can only operate from
the top element, so accessing an element in the middle or bottom requires removing all
elements above it, which wastes time and resources. Therefore, stacks are not suitable
for searching or sorting algorithms.
• Memory management in a stack can also be difficult, especially when elements are fre-
quently pushed and popped, often causing memory fragmentation. With programs that
have many recursive function calls, the stack can overflow quickly if the recursion depth
is too large, causing program errors. 3 Applications of Stack
The stack is an important data structure and is widely used in many applications and
algorithms. Thanks to the LIFO principle, a stack is very suitable for problems that require
reversing order, storing temporary states, and managing operation history. Typical applications of the stack include:
• Call Stack: A stack is used to store information for each function call, including local
variables, parameters, and return addresses. This mechanism is essential for executing programs that use recursion.
• Processing and converting mathematical expressions: A stack supports conversion from
infix to postfix or prefix forms, and is also used to evaluate these expressions by push-
ing/popping operands and operators. Therefore, it is commonly used in compilers and
mathematical processing systems.
• Checking valid parentheses and syntax: In syntax analysis, a stack can check the correct-
ness of bracket pairs such as (), ,[] and helps detect syntax errors in programs.
• Undo/Redo: A stack is used to store the most recent user actions. Therefore, software
such as Word, Photoshop, or editors can support undo and redo functionality.
• Back/Forward: The browsing history of web pages visited by the user is stored in a stack.
When the user presses Back or Forward, the browser retrieves the appropriate page from the stack to display.
• Depth-first search (DFS): A stack is used in DFS to traverse graphs, traverse trees, or
solve maze/backtracking problems.
• Reversing data: A stack allows reversing a string or array easily by pushing elements into
the stack and then popping them out following the LIFO principle.
• Transaction history management: In banking applications or financial transaction sys-
tems, stacks are used to store the most recent transactions, supporting review or undo operations when necessary. Conclusion
Through the implementation process, it can be seen that the stack is a data structure
that plays an important role in computer science and software development. With the LIFO
principle, the stack allows efficient data management and execution order, especially in recur-
sion problems, state management, and stack processing.
Although it still has some limitations such as limited storage capacity and lack of ran-
dom access support, the stack remains a simple, high-performance data structure with wide
applications. Mastering the stack is an important foundation for approaching more advanced
data structures and algorithms in future learning and software development. References
• Data Structures and Algorithms textbook
• Wikipedia – Stack (Data Structure)
• MDN Web Docs – JavaScript
• Basic HTML and CSS documentation