Published: 20 Feb 2025 | Reading Time: 4 min read
ADT—which stands for Abstract Data Type in Data Structure—refers to a user-created data type that defines all the operations that can be performed on the data and the behaviour of those specified operations without revealing the background gears running to implement the operations.
In simple terms, we can define abstract data type by saying that it does not go into detail about how memory and algorithms are organized within operations. The term "abstract" here refers to the fact that ADT data structures provide a hidden view.
This process of hiding unnecessary information that may confuse the user and providing only relevant information is called data abstraction in the data structure. Simply put, it shows us "what" rather than "how".
Abstract Data Type in python can thus be used to create efficient, reusable and scalable data structures, some common examples for which include Stack Abstract Data Type, Queue, Set, Map and Graph.
An ADT data structure can be implemented using various data structures. The difference is that ADT is an abstract concept defining behaviour and what operations can be performed, whereas data structures such as arrays, linked lists etc help with concrete implementation of ADT data structures and their operations.
Abstraction refers to the process of providing only essential information and hiding unnecessary details. It is done with the help of abstract data type in data structures as they provide a restricted view that does not show how operation implementation or organisation in memory is done.
A user-defined data type (UDT) is a data type that's created by a user to store and organize related information in one place. UDTs can be used to store a variety of information, such as financial records, inventory, and customer information. They allow users to create a data type specific to their needs by extending data types already provided.
| Properties | Abstract Data Type | User-Defined Data Type |
|---|---|---|
| Work | Ensures hiding data and operations that can be performed on that data. Operations that can be performed on the data as well as how they behave are also defined. | Gives a list of operations that can be performed as well as how they work. Programmers create these custom data types by combining or extending existing data types. |
| Use Cases | ADTs can be used to formulate and design data structures | UDTs are used to implement the concepts introduced by ADT data structures |
| Purpose | It gives us a conceptual surface view of the data structures and their functionalities, hiding all complicated details | It creates new specific data structures made by combining or extending the basic primitive data structures |
| Implementation | Does not go into details about data structure or how operations are performed | Gives details on how to create data structures and organize data |
| Examples | List ADT, Stack ADT, Queue ADT | Structures, Union, Classes |
This component can be further broken down into the type of data that we define Abstract Data Type stores and the structure of that data, that is, how it is stored. Types of data mainly refer to integers, strings, objects etc. These can be considered the ingredients or flavours of our dish. The structure of our data can be linear, hierarchical or graph-like, examples for which are shown in the figure. These are like the arrangement of the ingredients within a dish, the way they are placed on the serving plate.
Operations in Abstract Data Type in data structure are usually of 3 types:
These rules and constraints are in place to define how the operations interact with the data in Abstract Data Type data structure.
It describes the behaviour of the ADT when subjected to different operations and inputs.
In this type of ADT elements are arranged linearly or in a sequential structure. They act as building blocks for more complex structures as they are easier to implement. Examples of linear ADT are:
An ordered collection of elements that allows duplicates. It is easy to implement and traverse for sequential operations. The list consists of nodes that are used for data storage. All nodes are linked to one another, and therefore each node has the address for another block.
Essential Operations in List ADT:
A Last-In-First-Out (LIFO) structure where elements can only be added and removed from the top. It has two operations, one is to insert data to the top of the stack, also called push. The other is to remove data from the stack, which is called pop. It is efficient in memory usage as it operates in a single direction.
Essential Operations in Stack ADT:
A First-In-First-Out (FIFO) structure where elements are added at the end and removed from the front. It ensures order is maintained in processing and is ideal for task scheduling, resource sharing and buffering.
Essential Operations in Queue ADT:
It is a double ended queue where elements can be inserted and deleted at both the ends instead of just opposite ends. It can function as both a stack and a queue.
Essential Operations in Deque ADT:
In this type of ADT elements are arranged in a hierarchical or network structure. This allows for more complex relationships between the elements, which is ideal in real world situations. Examples include:
It is a hierarchical structure that starts at a root node and branches out into several child nodes, and then further their child nodes and so on. This structure facilitates fast searches, insertions and deletions in structures like Binary Search Trees (BST).
Essential Operations in Tree ADT:
It is a network arrangement of nodes where each node is connected to another by directed or undirected edges. It is convenient for representing real-world problems like social networks, road maps, and dependency graphs, and assists efficient pathfinding and connectivity checks.
Essential Operations in Graph ADT:
The specialized ADTs are designed for very specific purposes. They do not have fixed definitions, and the operations, properties or constraints are unique to a specialised ADT. Examples include but are not limited to:
It is a collection of unique elements that are stored in no particular order. A set efficiently manages duplicates in datasets, making it ideal for problems like membership testing.
Essential Operations in Set ADT:
It is a collection of key and value pairs, where each key represents a value. Values can be duplicate but keys must be unique. A dictionary or map provides quick lookups, making it ideal for caching, indexing, and configuration storage. It supports applications like database indexing.
Essential Operations in Map ADT:
It works like a queue, but each element in the queue has an assigned priority, and the element with the highest priority is removed or dequeued first. It is efficient for scheduling tasks where priority matters, like CPU scheduling.
Essential Operations in Priority Queue ADT:
This constitutes separating the type of data and operations from how they are implemented, and allows the user to interact with the ADT through a well defined interface. The 'what' over the 'how' reduces excessive need for understanding for the user, making ADT data structure easier to work with.
Modularity refers to dividing complex systems into smaller sections, where each section can be used to perform a specific task. ADT promotes modularity in programming, as the changes to its implementation do not affect the rest of the code as long as the interface remains the same. Example: A Stack ADT is modular because all stack-related operations are grouped together, independent of other parts of the system.
An ADT once created, such as a Queue or a Map can be reused in other codes or applications without needing to modify or re-create it. This increases reusability of code. Code written using ADT data structures is more readable and intuitive because it focuses on the operations rather than the implementation.
A single ADT can have multiple implementations, depending on the need of the task at hand. These implementations can be changed by a developer, without affecting the ADTs interface. Example: A List can be implemented using arrays for random access or linked lists for dynamic memory management.
ADT preserves data integrity as the high-level interface does not allow any modifications to data or implementation via controlled access to the developer. It also allows hiding sensitive information about the data that developers might not want unauthorized users to see.
Often ADTs can be made to mimic real-world scenarios, which makes solution mapping for problems easier and simpler. Example: A Queue mimics task scheduling in operating systems.
Using ADTs may result in overhead in terms of memory and processing due to encapsulation and abstraction. This may affect performance.
Some ADTs are not very flexible in terms of functionality, or they may not work well with all types of data structures.
ADTs limit the control a programmer can have over the data structures, which can cause restrictions in certain scenarios.
ADTs are not easy to understand and they can increase complexity when used for large and complex data structures.
Implementation of complex operations due to ADTs may increase costs due to required additional resources.
Compared to a custom data structure, ADTs don't always perform most efficiently for a specific application.
Abstract Data Types (ADTs) play a vital role in data structures by focusing on "what" operations are performed rather than "how" they are implemented. ADTs like Stacks, Queues, Lists, Trees, and Graphs offer reusable, modular, and adaptable building blocks for solving a wide range of real-world problems.
Specialized ADTs like Maps, Sets, and Priority Queues address specific needs, such as managing unique elements, key-value associations, or priority-based tasks, providing practical solutions for tasks like database indexing, caching, and task scheduling.
An Abstract Data Type (ADT) is a data structure that is defined by its operations and behavior rather than by its implementation. It specifies the operations that can be performed on the data but not how these operations are implemented.
ADT stands for Abstract Data Type.
The term "ADT" is still commonly used. However, in some contexts, people might refer to it as an "Abstract Data Structure" or simply a "Data Structure."
An abstract class in data structures is a class that cannot be instantiated on its own and serves as a blueprint for other classes. It can contain abstract methods that must be implemented by subclasses.
A list in DSA is a collection of elements arranged in a linear sequence, where each element points to the next. It supports operations like insertion, deletion, and accessing elements by their position, often implemented as arrays or linked lists.
Source: NxtWave - CCBP Blog
Original URL: https://www.ccbp.in/blog/articles/abstract-data-type-in-data-structure