Abstract Data Type
Term added on Tuesday 11th June, 2024 by Team
An Abstract Data Type (ADT) is a theoretical concept in computer science used to describe a data structure and the operations that can be performed on it, without specifying how the data structure is implemented. It focuses on what the data type does, rather than how it does it.
Key Points of an ADT
- Abstraction: ADTs provide a high-level interface to data, hiding the implementation details.
- Operations: They define a set of operations that can be performed on the data.
- Encapsulation: ADTs encapsulate data and the operations on that data, ensuring that the data is only accessible through these operations.
Why Use ADTs?
- Modularity: Encourages the separation of concerns by dividing the program into smaller, manageable pieces.
- Reusability: Allows you to reuse the ADT in different programs without modifying the implementation.
- Maintainability: Simplifies maintenance and updates, since changes to the implementation do not affect the interface.
Examples of ADTs
Here are a few common ADTs and the operations typically associated with them:
1. Stack
A stack is a collection of elements with two main operations:
- push: Add an element to the top of the stack.
- pop: Remove and return the top element of the stack.
Other possible operations:
- peek: Return the top element without removing it.
- is_empty: Check if the stack is empty.
- size: Return the number of elements in the stack.
2. Queue
A queue is a collection of elements with two main operations:
- enqueue: Add an element to the end of the queue.
- dequeue: Remove and return the element from the front of the queue.
Other possible operations:
- is_empty: Check if the queue is empty.
- size: Return the number of elements in the queue.
3. List
A list is a collection of elements with operations such as:
- insert: Add an element at a specific position.
- delete: Remove an element from a specific position.
- search: Find an element by its value.
- access: Retrieve an element at a specific position.