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.
Grading grid
P1 P2 P3 M1 M2 M3 D1 D2
Summative Feedback: Resubmission Feedback:
IV Signature:
Table of Contents
Data structures ............................................................................................................................................................. 4
1. Abstract data type (P1) ......................................................................................................................................... 4
Definition .................................................................................................................................................................. 4
Queue Data Structure ............................................................................................................................................... 5
2. ADT usages ............................................................................................................................................................ 9
Application of Stack in memory (P2) ........................................................................................................................ 9
Application of an ADT (P3) ...................................................................................................................................... 12
3. References .......................................................................................................................................................... 19
Figures
Abstract Data Types (ADTs) serve as black boxes that shield users from the intricacies of how data
is stored and processed internally. Users of an ADT like List, Stack, or Queue don't require detailed
knowledge about how these data types are implemented. Instead, they focus solely on understanding
the functionalities and capabilities provided by these ADTs.
For instance, when using primitive data types such as int, float, or char, users employ them
without needing to understand the underlying mechanisms responsible for their functioning. Similarly,
with ADTs like List, Stack, and Queue, users need only grasp what operations these structures support
(such as adding, removing, or accessing elements) without concern for the specific methodologies
employed for these tasks.
In essence, ADTs act as abstractions that emphasize what actions can be performed on the data,
ensuring users are shielded from the complexities of how these actions are executed within the ADT's
internal structure and design.
Queue Data Structure
What is a queue
A queue represents a valuable programming data structure. It functions akin to the line of people
waiting for tickets outside a movie theater, where the individual who arrives first is also the first to
receive a ticket.
The queue operates based on the principle of First In, First Out (FIFO), where the item entering the
queue earliest is the one to be retrieved first.
In the provided illustration, because 1 entered the queue ahead of 2, it's also the initial item to be
taken out of the queue, adhering to the FIFO principle.
In programming terminology, adding elements to the queue is termed "enqueue," while extracting
elements from the queue is termed "dequeue." Although the implementation of a queue can be carried
out in various programming languages such as C, C++, Java, Python, or C#, the fundamental specifications
remain largely consistent.
An everyday instance illustrating a queue could be a single-lane, one-way street where cars enter in a
sequence and depart in the same order they arrived. This concept is akin to practical scenarios like
waiting in lines at ticket gates and bus stops.
Result of program
Figure 8 Result of program
2. ADT usages
Application of Stack in memory (P2)
What is Stack Memory in computer.
In Java, stack memory serves for static memory allocation and executing a single thread. It holds
method-specific primitive values and object references from methods stored in the heap. This memory
operates on a Last In First Out (LIFO) order for access.
Figure 9 Stack memory
Each function instance demands memory allocation. Throughout the period from when a
function is called to when it completes, the activation record in memory for that function must contain:
- Storage for local parameters, local variables, and any additional space required by the compiler to
execute the function's code block.
- Information on how and where to resume execution after the function call concludes.
This allocated block of memory for each function instance is known as an activation record. The
memory within this activation record remains valid only while the function is actively executing; once the
function exits, this memory is reclaimed.
Before adding a component onto the stack, a "push" operation is executed. This operation
involves placing the new element at the stack's top. However, prior to inserting the value, it's essential to
verify if the current position of the top element (referred to as TOP) equals MAX - 1. This check is
necessary because if this condition holds true, indicating that the stack is at its maximum capacity, no
further insertions can occur. In the event that an attempt is made to insert a value into a full stack, an
"OVERFLOW" message will be displayed.
Figure 11 Push Operation
Example code
Result
- However, the Java ArrayList class may run slower as it involves considerable shifting of elements when
items are removed from the list.
The program will provide a user-friendly interface to manipulate objects within an ArrayList, allowing
programmers to leverage these features without worrying about the underlying implementation details.
Implement program
My program has functions such as: Add new students, view student list, Delete students, ...
Code of program:
Figure 15 Code of program
Figure 16 Code of program
Figure 17 Code of program
Result of program
Add Student
Delete Student
3. References
1. GeeksforGeeks. (2017). Abstract Data Types - GeeksforGeeks. [online] Available at:
[https://www.geeksforgeeks.org/abstract-data-types/](https://www.geeksforgeeks.org/abstract-data-types/).
3. Baeldung. (2018). Stack Memory and Heap Space in Java | Baeldung. [online] Available at:
[https://www.baeldung.com/java-stack-heap#:~:text=2](https://www.baeldung.com/java-stack-heap#:~:text=2).
Accessed 21 Aug. 2022.
4. Tutorialspoint.com. (n.d.). Data Structure and Algorithms Tutorial - Tutorialspoint. [online] Available at:
[https://www.tutorialspoint.com/data_structures_algorithms](https://www.tutorialspoint.com/data_structures_a
lgorithms).