What is Abstract Data Type (ADT)? - Data Structures Blog

What is Abstract Data Type (ADT)?

Abstract Data Type (ADT) is a mathematical model in programming that describes how a Data Structure should appear externally and what it can do.

To understand this, think that you are using some gadget.

1. Abstraction

  • 'Abstract' means hide. In ADT, we hide the Implementation Details (how that Data Structure is built internally).
  • The user only knows what operations that Data Structure can perform, but does not know how that work is happening inside.

2. What is Defined in ADT?

ADT defines three main things, not the way to implement it:

  • A. Data: What data it will hold. (e.g., Stack ADT will hold integers)
  • B. Operations (Functions): What operations can be performed on this Data Structure. (e.g., Stack ADT has Push, Pop, Peek operations).
  • C. Axioms/Constraints: What are the rules or limitations of these operations. (e.g., Pop operation will only happen when Stack is not empty).

3. Real-Life Example

  • Driving a Car:
  • When you drive a car, you only use Accelerator, Brake, and Steering. These are your Operations.
  • You do not need to worry about how fuel is burning inside the Engine, how gears are shifting, or how brake pads are working. All these are Implementation Details that are hidden from you.
  • A car is like an Abstract Data Type (ADT), where you are only given the interface.

Stack and Queue as ADT

You have read about Stack and Queue earlier. In programming, both are excellent examples of ADTs:

Data Structure Operations (External View) Implementation (Hidden View)
Stack ADT Push(), Pop(), Peek(), isEmpty() Can be built using Array or can be built using Linked List.
Queue ADT Enqueue(), Dequeue(), isFull(), isEmpty() Can be built using Array or can be built using Linked List.

Conclusion

ADT is a contract. It tells the user: "Give me this data, and you can perform these operations on me. You do not need to worry about how I am built internally."

Main Difference between ADT and Data Structure

Both are often understood as the same, but there is a fundamental difference between them that is related to Theory and Practice.

Feature Abstract Data Type (ADT) Data Structure
Concept Theoretical Model Concrete Implementation
What It Is? What the data is and what operations can be performed on it. How the data is organized and stored in memory.
Focus Interface and Behavior. Implementation and Memory Management.
Abstraction High Abstraction. Implementation Details are hidden. Low Abstraction. Implementation Details are shown.
Example Stack, Queue, List (They define Operations) Arrays, Linked Lists, Hash Tables (They store data)

Understand in Simple Language

1. Abstract Data Type (ADT) = Blueprint

  • ADT is just a design or blueprint.
  • It tells how a Data Structure should behave (like Stack's LIFO behavior) and what functions (Push, Pop) will be on it.
  • This is not code. It is just a specification.

Example: Stack is an ADT. It only defines LIFO rules.

2. Data Structure = The Built House

  • Data Structure is the real-world implementation of that ADT's blueprint.
  • It tells how Data will be physically organized in the computer's memory.
  • This is code that you actually write (like in C, Java, Python).

Example: You can use an Array (Static Allocation) or a Linked List (Dynamic Allocation) to implement Stack ADT. Array and Linked List are Data Structures here.

Conclusion

  • ADT tells you what to do.
  • Data Structure tells you how to do it.

You can use multiple different Data Structures (like Array or Linked List) to implement the same ADT (like Queue).

© 2023 Data Structures Insights. All rights reserved.

Comments

Popular posts from this blog

Data Abstraction

Data Structure Ka Parichay Aur Prakar (Introduction and Types of Data Structure)

Data Abstraction