Back

Abstract Data Type in Data Structure

20 Feb 2025
4 min read

Introduction to Abstract Data Type in Data Structure

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.

What Abstraction Means in Abstract Data Type in Data Structure

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.

What is User-Defined Data Types or UDTs

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. 

Difference Between ADTs and UDTs

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

Components of Abstract Data Type

1. Data 

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.

2. Operations

Operations in Abstract Data Type in data structure are usually of 3 types:

  • Constructor: This is the operation that initialises the ADT within our program. 
  • Accessor(Query): This type of operation retrieves data in ADT without modifying the data in any form. It can be considered as the waiter delivering our dish to our table without making any changes to how the chef prepared it. Examples include peek in a Stack, front in a Queue. 
  • Mutator(Modifier): This allows us to change the state of ADT. In other words, we use modifiers to make changes to the data stored in ADT. Consider it similar to requesting extra cheese or olives on your pasta; altering the original recipe of the dish. Examples for the same include push and pop in a stack, and enqueue and dequeue in a queue. 

3. Rules and Constraints

These rules and constraints are in place to define how the operations interact with the data in Abstract Data Type data structure. 

4. Behaviour

It describes the behaviour of the ADT when subjected to different operations and inputs. 

How Abstract Data Types are Classified

1. Linear Abstract Data Type

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:

List ADT

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.

custom img

Some of the most essential operations defined in List ADT are listed below.

  • front(): returns the value of the node present at the front of the list.
  • back(): returns the value of the node present at the back of the list.
  • pop_front(): removes the front node from the list.
  • pop_back(): removes the last node from the list.
  • get(): Return an element from the list at any given position.
  • insert(): Insert an element at any position in the list.
  • remove(): Remove the first occurrence of any element from a non-empty list.
  • removeAt(): Remove the element at a specified location from a non-empty list.
  • replace(): Replace an element at any position with another element.
  • size(): Return the number of elements in the list.
  • isEmpty(): Return true if the list is empty; otherwise, return false.
  • isFull(): Return true if the list is full; otherwise, return false.

Stack 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. 

custom img

Some of the most essential operations defined in Stack ADT are listed below.

  • push(x): Adds an element x to the top of the stack.
  • pop(): Removes and returns the element at the top of the stack.
  • peek()/top(): Retrieves the element at the top of the stack without removing it.
  • isEmpty(): Checks if the stack is empty.
  • size(): Returns the number of elements in the stack.

Queue 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.

custom img

Some of the most essential operations defined in Queue ADT are listed below.

  • enqueue(x)/add(x): Adds an element x to the rear of the queue.
  • dequeue()/poll(): Removes and returns the front element of the queue.
  • peek()/front(): Retrieves the front element without removing it.
  • isEmpty(): Checks if the queue is empty.
  • size(): Returns the number of elements in the queue.

Deque 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.

Some of the most essential operations defined in Deque ADT are listed below.

custom img
  • addFirst(x)/push_front(x): Adds an element x to the front.
  • addLast(x)/push_back(x): Adds an element x to the rear.
  • removeFirst()/pop_front(): Removes and returns the front element.
  • removeLast()/pop_back(): Removes and returns the rear element.
  • peekFirst()/front(): Retrieves the front element without removing it.
  • peekLast()/back(): Retrieves the rear element without removing it.
  • isEmpty(): Checks if the deque is empty.
  • size(): Returns the number of elements in the deque.

2. Non-Linear Abstract Data Type

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:

Tree 

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). 

custom img

Some of the most essential operations defined in Tree ADT are listed below.

  • insert(x): Adds an element x into the tree.
  • delete(x): Removes an element x from the tree.
  • search(x): Searches for an element x in the tree.
  • traverse(): Visits all nodes (e.g., in-order, pre-order, post-order, level-order).
  • findMin(): Finds the smallest element in the tree.
  • findMax(): Finds the largest element in the tree.
  • height(): Returns the height of the tree.

Graph

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. 

custom img

Some of the most essential operations defined in Graph ADT are listed below.

  • addVertex(v): Adds a vertex v to the graph.
  • addEdge(u, v): Adds an edge between vertices u and v.
  • removeVertex(v): Removes a vertex v and its associated edges.
  • removeEdge(u, v): Removes the edge between u and v.
  • getNeighbors(v): Returns the adjacent vertices of v.
  • isConnected(u, v): Checks if there is a path between u and v.
  • traverse(): Visits all nodes (e.g., BFS, DFS).
  • shortestPath(u, v): Finds the shortest path between vertices u and v (if weighted, Dijkstra or similar).

3. Specialized Abstract Data Type

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:

Set 

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.

custom img

Some of the most essential operations defined in Set ADT are listed below.

  • add(x): Adds an element x to the set (if not already present).
  • remove(x): Removes an element x from the set.
  • contains(x): Checks if the element x exists in the set.
  • union(s): Returns a new set with elements from both sets.
  • intersection(s): Returns a new set with elements common to both sets.
  • difference(s): Returns a new set with elements in the current set but not in s.
  • isEmpty(): Checks if the set is empty.
  • size(): Returns the number of elements in the set.

Map/Dictionary

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.

custom img

Some of the most essential operations defined in Map ADT are listed below.

  • put(key, value)/insert(key, value): Adds or updates the value for a key.
  • get(key): Retrieves the value associated with a key.
  • remove(key): Removes the key-value pair for a key.
  • containsKey(key): Checks if a key exists in the map.
  • containsValue(value): Checks if a value exists in the map.
  • isEmpty(): Checks if the map is empty.
  • size(): Returns the number of key-value pairs in the map.
  • keys(): Returns a set of all keys.
  • values(): Returns a collection of all values.

Priority Queue 

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.

Some of the most essential operations defined in Priority Queue ADT are listed below.

  • enqueue(x, priority)/add(x, priority): Adds an element x with an associated priority.
  • dequeue()/poll(): Removes and returns the element with the highest priority (or smallest, depending on implementation).
  • peek(): Retrieves the element with the highest priority without removing it.
  • isEmpty(): Checks if the priority queue is empty.
  • size(): Returns the number of elements in the priority queue.

Benefits of using Abstract Data Types

1. Encapsulation and Abstraction 

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. 

2. Modularity

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.

3. Reusability and Readability

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.

4. Flexibility and Adaptability

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.

5. Data Integrity

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. 

6. Real World Problem Solving

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.

Disadvantages of using Abstract Data Types

1. Overhead:

Using ADTs may result in overhead in terms of memory and processing due to encapsulation and abstraction. This may affect performance. 

2. Limited flexibility:

Some ADTs are not very flexible in terms of functionality, or they may not work well with all types of data structures.

3. Limited control:

ADTs limit the control a programmer can have over the data structures, which can cause restrictions in certain scenarios.

4. Complexity:

ADTs are not easy to understand and they can increase complexity when used for large and complex data structures.

5. Cost:

Implementation of complex operations due to ADTs may increase costs due to required additional resources.

6. Performance:

Compared to a custom data structure, ADTs don’t always perform most efficiently for a specific application.

Conclusion

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.

Frequently Asked Questions

1. What is an Abstract Data Type (ADT)?

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.

2. What does ADT stand for?

ADT stands for Abstract Data Type.

3. What is the new name of ADT?

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."

4. What is an Abstract Class in 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.

5. What is a list in DSA (Data Structures and Algorithms)?

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.

Read More Articles

Chat with us
Chat with us
Talk to career expert