Resources | Subject Notes | Computer Science
An Abstract Data Type (ADT) is a mathematical model that defines a set of data and the operations that can be performed on that data. It focuses on *what* the data type does, rather than *how* it is implemented.
Think of an ADT as a blueprint. It specifies the behavior of a data structure without specifying the underlying implementation. This allows for flexibility in how the ADT is implemented (e.g., using an array, a linked list, etc.) without changing the interface.
Key characteristics of an ADT:
A stack is an ADT that follows the Last-In, First-Out (LIFO) principle. Imagine a stack of plates – the last plate added is the first one removed.
Common Stack Operations:
Implementation Options:
A queue is an ADT that follows the First-In, First-Out (FIFO) principle. Imagine a queue of people – the first person in line is the first one served.
Common Queue Operations:
Implementation Options:
A linked list is an ADT where elements are stored in nodes, and each node contains a data value and a pointer (or link) to the next node in the sequence. It does not require contiguous memory allocation.
Common Linked List Operations:
Implementation:
A linked list typically consists of a series of nodes. Each node contains:
We can use the ADTs discussed above (stack, queue, linked list) to store data in various ways. The choice of ADT depends on the specific requirements of the application.
For example:
Feature | Stack | Queue | Linked List |
---|---|---|---|
Data Order | LIFO | FIFO | Sequential (can be ordered based on pointers) |
Insertion | Top | Rear | Can be inserted at any position |
Deletion | Top | Front | Can be deleted from any position |
Memory Allocation | Can be static or dynamic | Can be static or dynamic | Dynamic |
Efficiency (Typical) | O(1) for push/pop | O(1) for enqueue/dequeue | O(1) for insertion/deletion at known position, O(n) for search |