Abstract data type, Explanations, Examples and Advantage

The abstract data type (ADT) is a data type that focuses on what it does by ignoring how it does.

In other words, an ADT is defined by its operations and their semantics, rather than by its implementation.

The Best example of this Abstract data type is Stack and Queue. Stack having its push and pop operations, but it is implemented using the array or linked list. There is also a complex logic behind the push and pop operations of the stack, but we never focus on that.

ADT Explanations

  1. Data and Operations: ADT focuses on what operations are to be performed but not on how these operations will be implemented. It encapsulates the data and provides an interface to the user.
  2. Abstraction: ADTs provide a level of abstraction, allowing users to know what operations are performed but not how they are performed. This abstraction enables changing the implementation without altering the interface.
  3. Modularity: ADTs help in building modular and reusable code. The implementation details are hidden, allowing for independent development of ADTs and their implementations.


Lets spread Abstract data type in two parts “Abstract” and “data type” to understand it well.

Data Type

Data type describes the variables, is the set of values that the variable can take. We have already seen previously. Some basic data types in C are int, char, float, and double.
When we talk about a primitive type data type, basically we consider two things: one is a data an item with certain characteristics and another one is permissible operations on that data.
For example, an int variable can contain the value from –32768 to 32767 and can be operated with the operators +, –, *, and /.
Therefore, If we declare a variable of an abstract data type (e.g., stack or a queue), then the above operations that should also be performed on it.

Abstract

The word ‘abstract’ means hide the complex internal implementation, only show the functionality.
In C, an abstract data type can be a structure considered only its functionality without regard to its implementation. This structure has any numbers of methods that are defined to perform various tasks. This method is already defined, but the end-user is not concerned about the internal implementation of these methods, and also end-users are not aware of how that methods carry out their tasks.
They are only aware of the methods name and their operations that are available and documented. They are only concerned about how to call these methods and to get the results after the computation by these methods. They are not concerned about how they work.

For example, 

In a stack or a queue data structures, there are some specified predefined operations. Like On stack data structure, we can apply push and pop operations. The users have concerned only with that the type of data and the operations that can be performed on it. But the users are not aware of how the data is stored in the memory. They should not be concerned with how the methods work or what structures are being used to store the data.
For the stack, data structure user should just know that the stack has push() and pop() functions. Using these functions push() and pop(), user can manipulate the data (insertion or deletion) stored in the stack.

ADT Examples

Examples

  1. Stack:
    • Operations: Push, Pop, Peek, isEmpty
    • Description: A stack is an ADT that follows the Last-In-First-Out (LIFO) principle. Elements are added (pushed) and removed (popped) from the top of the stack.
  2. Queue:
    • Operations: Enqueue, Dequeue, Front, isEmpty
    • Description: A queue is an ADT that follows the First-In-First-Out (FIFO) principle. Elements are added (enqueued) at the rear and removed (dequeued) from the front.
  3. List:
    • Operations: Insert, Delete, Find, isEmpty
    • Description: A list ADT allows for the storage and retrieval of data at specific positions. It can be implemented as a linked list, array list, etc.
  4. Tree:
    • Operations: Insert, Delete, Traverse
    • Description: A tree ADT allows for hierarchical data storage. It’s used in various forms like binary trees, AVL trees, etc.
  5. Graph:
    • Operations: AddVertex, AddEdge, RemoveVertex, RemoveEdge
    • Description: A graph ADT represents a set of connections or relationships. It consists of vertices (nodes) and edges (connections).

Advantages of Abstract Data Type

  • ADT is robust and reusable.
  • It is based on the principles of Object-Oriented Programming (OOP) and Software Engineering (SE).
  • An ADT can be re-used at several places, and it reduces the coding efforts
  • ADT ensures a robust data structure
  • Allows better conceptualisation and modelling of the real world

ADT approach is based on the SE concepts of coupling and cohesion Coupling property determines

  • How strongly two separate parts of programs are linked together
  • Extend to which changes made in one part impacts the other parts of a software module

Well, designed software has a minimum coupling. An ADT promotes weak coupling. Cohesion determines how well-integrated are components of the software. An ADT inherently promotes maximum cohesion.

Leave a Comment