ASM1-Data-Structures-Algorithms-DONG DUC THANH-BS00138.123
ASM1-Data-Structures-Algorithms-DONG DUC THANH-BS00138.123
ASM1-Data-Structures-Algorithms-DONG DUC THANH-BS00138.123
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:
2
Table of Contents
List of figure.................................................................................................................................4
Introduction ...............................................................................................................................5
Create a design specification for data structures explaining the valid operations that can be
carried out on the structures (P1) ...............................................................................................6
1. Abstract data type ................................................................................................................6
1.1 Definition ............................................................................................................................6
1.2 Features of ADT: ................................................................................................................8
Determine the operations of a memory stack and how it is used to implement function calls in a
computer (P2) ........................................................................................................................... 23
1. Stack ADT .......................................................................................................................... 23
2. Overview stack operations .................................................................................................. 24
Using an imperative definition, specify the abstract data type for a software stack.Why did you
choose to describe the ADT in stack (P3) .................................................................................... 32
1. Using an imperative definition, specify your chosen ADT ...................................................... 33
3.These issues.......................................................................................................................... 33
4. The problem's resolute ........................................................................................................ 35
5. Application of ADT ............................................................................................................... 35
Conclusion ................................................................................................................................. 36
References ................................................................................................................................. 37
3
List of figure
4
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, I'll 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.
5
Create a design specification for data structures explaining the valid operations that can be
carried out on the structures (P1)
1. Abstract data type
1.1 Definition
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 carried out. There is a lack of specification on the chosen algorithms, the operations to be carried
out, and the data arrangement 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.
These are some instances of ADT:
• Stack: The last-in, first-out (LIFO) method of data storage is applied to a stack.
• Queue: A first-in, first-out (FIFO) sorting method is used to store data in a queue.
• Linked list: Information may be stored in a linked list manner using a linked list kind of data structure.
• Tree: Information is arranged hierarchically in a tree data structure.
These are a few typical categories of fundamental ADT axiomatic operations:
-Producer (+,-,*,/, decrease size on element deletion), accessor, converter, and creator (constructor).
List, Stack, and Queue are a few often used ADTs. The following is a synopsis of their access and
transformation operations:
6
Figure 1. ADT
7
List, Stack, and Queue are able to interact with the data of their instances thanks to these actions. The
wording in the activity name also alludes to each participant's unique goal and appropriate conduct.
Users may utilize the built-in functionalities without having to rewrite anything from start. It conceals
the difficulty of using the public features it offers users and merely makes them available. Time is saved
by the constant updating of ADT, which has been improved over time. Stacks, Queues, and Lists are
common ADTs.
1.2 Features of ADT:
Abstraction:
The user simply must know the bare minimum because the implementation of the data structure is
not required.
An improved conceptualization:
ADT gives us a more precise perspective of reality.
Robust:
The program is robust and capable of identifying errors.
Encapsulation:
ADTs conceal the underlying properties of the data while providing a public interface for people
to interact with it. This makes it easier to maintain and modify the data structure.
Abstraction of Data:
ADTs provide a certain level of abstraction from the implementation details of the data. It is
sufficient for users to know what operations may be performed on the data, not how those actions
are performed.
8
Information Withholding:
The only way ADTs can protect the integrity of the data is by granting access to authorized users
and operations. This reduces the possibility of errors and misuse of data.
Modularity:
Joining ADTs together can produce larger, more intricate data structures. This may have made
programming more modular and adaptable.
Benefits
Encapsulation:
ADTs provide a way to merge data and actions into a single unit, making the data structure simpler
to maintain and modify.
Abstraction:
Utilizing ADTs, which let users to work with data structures without being aware of the
implementation details, can simplify programming and reduce the likelihood of mistakes.
Disadvantag
Overhead
:
The implementation of ADTs may result in memory and processing overhead that affects
performance.
Complexity:
ADT construction may be challenging, particularly for large and complex data structures.
Curve of Learning
It may take some time and effort to become proficient in ADT implementation and usage, which
is necessary in order to use them.
Limited adaptability:
Certain ADTs might not be suitable for all types of data structures or fully functioning.
9
Cost:
The application of ADTs may increase the cost of development, requiring additional financing and
expenditure.
Abstract data types can be portrayed in several ways that are widespread. The most typical
ones are as follows:
Interfaces: A contract that lists the methods a type has to have is called an interface. It doesn't say
how those methods are applied. This allows for several implementations of the same interface,
which can improve speed and flexibility.
Abstract classes: An abstract class is one that cannot be instantiated directly. Subclassing it and
having the subclass implement the abstract methods of the abstract class are prerequisites. Code
reuse is made possible by defining comparable functionality for a group of related classes.
Database structures: An abstract data type that is realized in material form is called a data structure.
It provides a sophisticated data management and storage solution. The use of data structures can
improve the efficiency of operations on data.
There are several ways to represent abstract data types, depending on the specific needs of the
application. An abstract class or data structure could be a better fit in some situations, but an
interface might be the best choice in others.
An ADT may be represented using a data structure and a set of operations in more depth by
following these steps:
Step 1: Assemble the data structure. The data structure that will be used to hold the ADT must first
be defined. The requirements of the ADT should be taken into consideration while selecting a data
structure.
10
EX: For example, because it allows for efficient insertion and removal of items at the list's
beginning, a linked list is a great substitute for a stack. Give specifics on the operations.
Step 2: Defining the operations that will be accessible for communicating with the ADT is the next
stage. It is important to specify the operations in a fashion that aligns with the abstract behavior of
the ADT.
EX: As an example, an element should be added to the top of a stack by the push operation and
removed from the top of the stack by the pop action. Utilize the data structure and the procedures.
Step 3: The final step is implementing the data structure and operations in a computer language.
various programming languages will have various implementations for the data structure and
operations.
Here are some examples of how different programming languages can represent abstract data types:
Java: Abstract data types can be described using abstract classes and
interfaces.
C++: In C++, abstract data types can be described using abstract
classes.
Python: Abstract data types can be expressed using abstract base classes.
It is important to keep in mind that different terms are sometimes used to describe different abstract
data types. A design decision regarding utilizing a representation for an abstract data type should be
made based on those application-specific requirements.
1. Examples
11
Singly-linked-list
Data is organized using a linked list data structure when the amount of data values is uncertain. Each
entry in a linked list is connected to the element that comes after it, forming a linear data structure.
A "Button" is the name given to each item in the connected list. The first kind of linked lists that we
shall discuss are singly linked lists. One kind of one-way linked list that can only be accessed by
going from the first to the final node is called a sininglynked list.
12
Figure 4. Node in a singly linked list
- Insertion
- Deletion
- Display
To begin, we need to create an empty list by using the following technique to carry out the
previously mentioned steps:
Step 1: Check to make sure all header files for the application are there.
13
Step 4: Assign the Node reference a "head" and set its value to NULL.
Step 5: Execute the selected operation by the user by presenting an operations menu, calling the
appropriate methods within the main function, and completing the activity.
a. Insertion
After the list is formed, we may add data to it. There are three different ways to carry out the
insertion operation in a single linked list.
• Adding at the start of a list; • Adding at the conclusion of a list
• Putting anything in a list at a certain place
14
Adding at the beginning of a list
15
Adding at the end of the list
16
b. Deletion
A single linked list can have entries removed in three different methods. Here are the specifics:
17
Figure 8. Deleting the first node of a singly linked list
18
c. Display
First, we will create a Java class named Node with many ADT-related attributes and methods, as well
as a file named singly linked list. It transcends mere declarations without clarification. The variable size
of a single linked list is the number of elements in it. Its node's two data fields are Info and Next Nodal
The next step is to construct a Java class called "singly LinkedList"; it is sometimes shortened as
"SLLLlist," but we may change that and put a word list behind it. Make the Round List & Check
function public. A variety of techniques, including add, delete, find, and empty list, will be
developed. A value will be added at an index using the add method. The former components in a
place are pushed back when a value is added there.
19
20
Figure 14. Example of ADT (2)
The delete method confirms that the index was previously valid while removing the value from it. The
get method will retrieve the value of the requested index, including delete tail, delete Node, delete head,
etc.We usually write a note after creating a line of code so that we may assess its purpose later.
To print the outcome, the user must simply utilize this ADT-called function to print the entire ring
list.
21
Figure 15. Example of ADT (4)
22
Figure 17. Code Circular Linked List
The stack is represented by a stack of disks; to remove the bottom disk, you must first remove the
top disk; to add a new disk, you must first place the top disk.
A stack of disks is used to symbolize the stack; It is necessary to remove the top disk before
removing the bottom disc; You have to insert the top disk before you can add another.
23
Figure 18. Stack
An operational clause number with a designated operation duration is assigned to each of the two
alterations that the stack is most likely to encounter. Consider the data argument as an integer data
type to make things easier:
Push(int) :
An operation known as "push" occurs when an element is added to the top of a stack.
24
Figure 19. Push stack operation
• The element argument is inserted and stored at the top of the stack using the "push" method.
• Each stack also has a certain capacity, so if the stack is not filled, the "push" operation can still be
used. The push operation mechanism will throw a "stack overflow" exception if the stack is full
and the push operation is still called to insert an element.
• The push mechanism returns the value of the inserted element when an element is successfully
pushed.
Int pop() :
"Pop" refers to the process of removing an element from the stack that is at the top.
25
Figure 21. A pop operation
• The "pop" action retrieves the most recent element added to the stack or removes the last
(top) element from it. This operation technique involves the order of the input and output
elements since the final input element is also the first drawn element.
• Calling the "pop" function while the stack is empty leads to stack overflow.
• In this scenario, a "null pointer exception" or another "RuntimeException" will be thrown
instantly by the underlining condition of the "pop" function as well.
• The deleted element's integer value is returned by the "pop" operation.
Int peekTop() :
The "PeekTop" action, unlike the "pop" function, fetches and returns the top (last) integer element
in the stack.
26
Figure 22. PeekTop Operation Illustration
Similar to the "Pop" action, stack underflow will occur if the stack is empty but the "PeekTop"
function is still called. In the event that this happens, the underflow condition of the "PeekTop"
function will immediately issue a "null pointer exception" or another "RuntimeException".
Boolean isEmpty() :
It is required to continuously check if the stack is empty while doing further operations (like "pop"
or "peek top") by counting the number of components that are now present before choosing whether
to continue out an algorithm or report an error.
"isEmpty" will be in charge of handling this.
27
The top(last) element in the stack will be examined to see if it is present using the "isEmpty"
function. "isEmpty" returns true and the opposite if this element is absentTop()
• The peak or highest element of the stack is what this operation returns.
• Each push() or pop() action causes the value of the top to change.
3. Stack Memory
3.1 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.
28
Figure 25. Memory stack
Advantage
• It allows us to manage the data using the Last In First Out (LIFO) concept, which sets it apart 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.
•pop() - Remove and return the element at the top of the stack if it is not already empty.
29
•peek() - If the stack is not empty, it returns the element at the top of the stack without deleting it.
3.3 Application
Recursive function storage can be used, for example, to store the multi-function itself and its
variable result on the stack and wait for the results of the recursive multi-function below. The
subsequent calculation. The multi-function will be stored in an extra memory cell for each recursive
call. The stack memory is reclaimed when multi(1) returns 1 and multi(2), multi(3), and multi (6)
are computed. Lastly, assign a value to the resulting Main variable.
30
Figure 28. Stack memory example (2)
Data is stored in a stack in the LIFO (last in, first out) manner. In other words, the last item placed
to the stack is the first one taken off. In computer programming, stacks are frequently used to hold
temporary data, such local variables and function arguments. Memory is separated into two sections
31
in stack-based memory organization: the heap and the stack. Temporary data is kept in a limited,
fixedsize memory region called the stack. A bigger, variable-sized section of memory utilized for
longerterm data storage is called the heap. The CPU pushes local variables and function arguments
onto the stack when a function is called. The CPU retrieves the arguments and local variables from
when the function returns.
This guarantees that the data of the function is cleaned up appropriately upon function resumption.
Temporary data storage may be accomplished extremely well with stack-based memory
management. Because the CPU automatically maintains the stack for the programmer, it is also
incredibly simple to use. However, because the heap needs to be accessed each time data is added
or withdrawn, heap-based memory organization may not be the most effective way to store vast
quantities of data.
The following are some benefits of organizing memory with a stack:
Here are some of the advantages of using a stack for memory organization:
Efficiency: Stacks are very efficient for storing temporary data, as the CPU can access data on the
stack very quickly.
Ease of use: Stacks are very easy to use, as the CPU automatically manages the stack for the
programmer.
Here are some of the disadvantages of using a stack for memory organization:
Limited size: Stacks are limited in size, as they are a fixed-size region of memory.
Inefficiency for large data: Stacks are inefficient for storing large amounts of data, as the heap
must be accessed each time data is added or removed.
Overall, stack-based memory organization is a very efficient and easy-to-use way to store temporary
data. However, it is not a good choice for storing large amounts of data.
Using an imperative definition, specify the abstract data type for a software stack.Why
did you choose to describe the ADT in stack (P3)
ADT's definition simply addresses the tasks that will be carried out; it makes no mention of how they
will be carried out. It doesn't say which algorithms will be utilized to carry out the operations or how
the data will be arranged in memory. ADT is a useful tool that may assist programmers in writing
better code, which is why I chose to talk about its advantages. Users are able to concentrate on
functionality by simplifying the intricate nature of data structures through the abstraction offered by
32
ADT. The program's modularity is further enhanced by the fact that they enable the development of
data structures separately from the remainder of the program. Code is now easier to comprehend,
update, and reuse as a consequence.
The following is a summary of particular advantages of utilizing ADT:
Abstraction: ADT offers abstraction by insulating consumers from the particulars of data structure
construction. That makes the code easier to read and manage, and makes it easier to change the way
the data structure is implemented without changing the code that utilizes it.
Modularity: Because ADTs promote modularity, the data structure implementation can remain
separate from the rest of the application. As a consequence, the code is now easier to understand,
maintain, and reuse.
Reusability: ADTs can be used with many applications. This also saves time and effort since the code
is more likely to be consistent across several apps.
Robustness: ADTs can aid in improving the resilience of code by providing a clear definition of the
data structure and its functions. This makes it easier to identify issues and fix them as well as avoid
making mistakes in the first place.
I urge you to learn more about ADTs and how you can use them to enhance your code if you are a
programmer.
A structure having head and tail properties is the definition of an ADT linked list. The head and tail
fields, respectively, denote the first and last nodes in the list. The append() method adds a new node
to the end of the list, while the print() function shows the value of each node in the list. This is only
an example of the ADT definition for an imperative linked list. ADT linked lists have several
alternative definitions, the best of which will rely on the particular needs of the application.
3.These issues
I want to create an application that allows me to manage monthly car sales. Since there is only
one data type and its operations are implementation specific and no longer useful I tried using
data types but found it ineffective. I also use other ADTs from other programming languages,
such as Java, but they are also not sufficient for my purposes. Furthermore, I thought that since I
could create complex applications with many different functions, using a common data type
33
would not meet my needs or provide my application with the same features. Necessary features.
collective.
Insertion: Adds a new element to the list's first position.
34
4. The problem's resolute
Because the program will need to handle a range of data kinds, I decide to create an ADT (a new data
type), and its operations are defined by that data type. Can you meet your new expectations?
Programmers will be able to reuse code more effectively and adaptably thanks to ADT. I would make
use of a linked list to overcome that problem. The manager of the car store, the user, created ADT
with success.
5. Application of ADT
Once the application has been constructed, you must include the ADT using the proper methods. ADT
should be reviewed after use and modified as needed. This guarantees the consistency and reliability
of the program's abstract data type. Lastly, by linking this ADT to other features, the user may include
it into the program.
35
Conclusion
At last, I completed the conversation about creating a description of a data structure that enumerates
the permissible operations that can regulate data structure interactions. We'll go over how to handle
function calls using memory stack approaches.
Furthermore, construct an abstract data type for the program stack using the idea of order. An
example and particular data structure for a First In First Out (FIFO) queue are given. Compare the
bubble sort method's efficacy to that of the rapid sort approach. Completing the last tasks involves
comprehending the advantages of employing ADT for information concealing and encapsulating. I
also learnt the foundations of sorting algorithms and data structures after reading this report, which
will be very helpful to me in the future.
This is also a step toward ADT's goal of creating more technology-based communication solutions,
which will enable it to provide companies with exceptional marketing concepts and distinctive,
allinclusive experiences.
36
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 March
2024).
[2] Abstract data type in data structures (n.d) Online Courses and eBooks Library. Available at:
https://www.tutorialspoint.com/abstract-data-type-in-data-
structures#:~:text=The%20ADT%20is%20made%20of,Stack%2C%20Queue%2C%20List%
20etc. (Accessed: 28 March 2024).
[3] GfG (2023) Abstract data types, GeeksforGeeks. Available at:
https://www.geeksforgeeks.org/abstractdata-types/ (Accessed: 28 March 2024).
[4] Abstract data type in data structure - javatpoint (no date) www.javatpoint.com. Available at:
https://www.javatpoint.com/abstract-data-type-in-data-structure (Accessed: 28 March 2024).
[5] (No date) Chapter 5: Abstraction and abstract data types. Available at:
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:
https://www.baeldung.com/cs/adt (Accessed: 28 March 2024).
[7] What is Abstract Data Type?: Autoblocks Glossary (no date) Autoblocks. Available at:
https://www.autoblocks.ai/glossary/abstract-data-type (Accessed: 28 March 2024).
37
38