FINAL REPORT LeTrungDuc BH00954 DSA
FINAL REPORT LeTrungDuc BH00954 DSA
Unit number and title Unit 19: Data Structures and Algorithms
Plagiarism
Plagiarism is a particular form of cheating. Plagiarism must be avoided at all costs and students who break the rules, however innocently, may be
penalised. It is your responsibility to ensure that you understand correct referencing practices. As a university level student, you are expected to use
appropriate references throughout and keep carefully detailed notes of all your sources of materials for material you have used in your work,
including any material downloaded from the Internet. Please consult the relevant unit lecturer or your course tutor if you need any further advice.
Student Declaration
I certify that the assignment submission is entirely my own work and I fully understand the consequences of plagiarism. I declare that the work
submitted for assessment has been carried out without assistance other than that which is acceptable according to the rules of the specification. I
certify I have clearly referenced any sources and any artificial intelligence (AI) tools used in the work. I understand that making a false declaration is
a form of malpractice.
P1 P2 P3 P4 P5 P6 P7 M1 M2 M3 M4 M5 D1 D2 D3 D4
Summative Feedback: Resubmission Feedback:
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
I. Definition if abstract data type(ADT)
A type (or class) for objects whose behavior depends on a range of inputs and outputs is known as an
abstract data type, or ADT. The term "ADT" describes the necessary acts, not the method by which they
must be canied out. There is a lack of specification on the chosen algorithms, the operations to be carried
out, and the data anangement in memory. It's named "abstract" because it offers an
implementationunrelated point of view. An abstraction of a data structure that offers just operations and
conceals the implementation of those operations is called an abstract data type (ADT). They are frequently
used in object oriented programming languages and may be used to create classes and objects.
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
Abstract Data Types (ADTs) are essential in systems development as they provide a clear, high-level
representation of data and its associated operations. By defining a formal specification, ADTs bring
precision and consistency to system design, facilitating better error handling, modularity, and
maintainability. Examples such as stacks, queues, and linked lists demonstrate how ADTs can be
implemented through various concrete data structures, allowing developers to choose the most suitable
one for specific needs.
The use of ADTs enables developers to focus on the behavior of data rather than implementation
details, promoting robust and scalable system development. This abstraction not only enhances
collaboration among development teams but also supports the creation of flexible software that can adapt
to changing requirements without extensive rework. Overall, ADTs play a crucial role in streamlining the
development process and ensuring the integrity and efficiency of software systems.
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: