Part1 DSA LeTrungDuc BH00954
Part1 DSA LeTrungDuc BH00954
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:
A.Introduction
I have not received any assistance from this quest about the ADT that requested it. It offers a wealth of
detailed information about ADT, covering its definition, representation, stack memory, and other features.
Furthermore, Ill use the description to write software for the stack's abstract data type.
Subsequently, I discovered a few practical uses for ADT and stacks. We will discuss the benefits of
utilizing ADT for data encapsulation and obfuscation in the final section. I am now able to send the task
request and read the ADT request script.
B.Content
II. Design specification for data structures explaining the valid operations that can be
carried out on the structures (P1)
1. Linked List
a. Definition
A Linked List is a linear data structure where each element (called a node) contains a data part and a reference (or
pointer) to the next node in the sequence. This allows for efficient insertion and deletion of elements, as no shifting
of elements is required.
The linked list works through pointers. The first node is called the head. Each node points to the next
node, forming a chain-like structure. To traverse the list, you start from the head and follow the pointers
until you reach a node that points to null.
c. Code Example
2. Stack
a. Definition
A Stack is an abstract data type that follows the Last In First Out (LIFO) principle. It allows two main
operations: push (adding an item to the top) and pop (removing the item from the top).
c. Code Example
3. Queue
a. Definition
A Queue is a linear data structure that follows the First In First Out (FIFO) principle. The element that is
added first is the one that is removed first.
Queues can also be implemented using arrays or linked lists. The first element added is the first to be
removed, which is useful in scenarios that require order preservation such as scheduling tasks.
c. Code Example
III. Determine the operations of a memory stack and how it is used to implement function
calls in a computer. (P2)
1. Memory Stack
a. Define
In a Java Thread, stack memory is used to hold local variables for functions and function calls during
runtime. Primitive types, reference types to heap-based objects (reference types), declarations made in
functions, and arguments supplied to functions are examples of local variables. Stack memory is utilized
when a thread is running. The primary contents of stack memory are function calls, method-specific
temporary variables, primitive local variables, and pointers to other objects on the heap that the method is
referring to. One of the major uses of stack ADT is the last-in, first-out (LIFO) data storage technique,
which is always referred to as "stack".
Every time a method call is made in stack memory, a brand-new stack frame is generated to store
pointers to other objects (such an array, String, etc.) and local primitive values in function calls. The
function call terminates with the pop of the stack frame. The operating system limits the size of each
stack.
b. Advantage
It allows us to manage the data using the Last In First Out (LIFO) concept, which sets it apat from
linked lists and arrays.
When a function is called, local variables are allocated on a stack, which is promptly released upon
the function's return.
A stack is used if a variable is not used after that function's bounds.
This allows you to control memory allocation and deallocation.
Stack cleaning of objects is done automatically.
It is hard to corrupt.
Variables cannot be resized after they are declared.
Description: Adds a new item (stack frame or variable) onto the top of the stack.
Functionality: When a function is called, all its related information (local variables and return
address) is pushed onto the stack.
Pop:
Description: Removes the item (top stack frame) from the stack.
Functionality: When a function completes, the stack frame is popped, and control returns to the
previous function along with its local variables.
Description: Returns the top item of the stack without removing it.
Functionality: During execution, it can be used to inspect variables or the return address without
changing the state of the stack.
IsEmpty:
Get Size:
When a function is invoked, a new stack frame is created for that function's execution. This frame includes
the return address (where the control should return after the function finishes), local variables, and
parameters passed to the function.
The stack frame for the function call is pushed onto the stack, effectively saving the current state of the
program. This includes:
The CPU executes the function using the local variables and arguments stored in the stack frame. The
function can manipulate these variables as needed during its execution.
d. Function Completion:
Upon finishing, the function will typically encounter a return statement. This triggers the process
to pop the stack frame off the stack, removing all local variables and pointers associated with that
function. The return value, if any, may be passed back via the specific data return mechanisms defined by
the language.
e. Control Transfer:
The program control transfers back to the previously saved address, which is now at the top of the stack
(the calling function). The caller can now use the results from the callee (if applicable).
f. Memory Management:
Because of the stack's nature, once the function returns, the memory occupied by the local variables is
automatically reclaimed, reducing the risk of memory leaks and fragmentation.
IV. Using an imperative definition, specify the abstract data type for a software stack.
(P3)
1. Definition
An Abstract Data Type (ADT) Stack can be defined using an imperative specification, where the operations are
explicitly stated. Here is how the stack can be described:
These operations adhere to the Last In, First Out (LIFO) principle, where the last element added is the first one to
be removed.
C.Conlusion
D.References
[1] Introduction to stacks in Data Structures: Prepinsta (2023) PREP INSTA. Available at:
https://prepinsta.com/data-structures/introduction-to-stacks-in-data-structures/(Accessed: 28 March2024).
[2] Abstract data type in data structures (n.d) Online Courses and eBooks Library. Available at:
[4] Abstract data type in data structure - javatpoint (no date) www.javatpoint.com. Available at:.
https://www.geeksforgeeks.org/abstractdata-types/(Accessed: 28 March 2024).
https://web.engr.oregonstate.edu/~sinisa/courses/OSU/CS261/CS261_Textbook/Chapter05.pdf(Accessed:
28 March 2024).
[6] Datta, W. by: S. (2024) What is Abstract Data Type?, Baeldung on Computer Science. Available at:
[7] What is Abstract Data Type?: Autoblocks Glossary (no date) Autoblocks. Available at: