Resources | Subject Notes | Computer Science
An Abstract Data Type (ADT) is a theoretical model of data structure that defines a set of operations and their behavior, without specifying how the data is stored. It focuses on what the data structure does, rather than how it is implemented.
Think of an ADT as a contract. It specifies the interface – the operations you can perform – and the expected results, but leaves the internal implementation details hidden.
This abstraction allows for flexibility in implementation. The same ADT can be implemented using different underlying data structures (e.g., an array, a linked list) without affecting the code that uses the ADT.
Common examples of ADTs include stacks, queues, and linked lists. These are fundamental building blocks in computer science.
A stack is an ADT that follows the Last-In, First-Out (LIFO) principle. Imagine a stack of plates – the last plate you put on is the first one you take off.
Example Use Case: Function call stack in programming languages.
A queue is an ADT that follows the First-In, First-Out (FIFO) principle. Think of a queue of people waiting in line – the first person in line is the first one served.
Example Use Case: Print queue, task scheduling in operating systems.
A linked list is an ADT where elements are stored in nodes, and each node contains a data element and a pointer (or link) to the next node in the sequence. It's a linear collection of data.
Example Use Case: Implementing stacks, queues, and other complex data structures; representing dynamic lists.
ADT | Principle | Key Operations | Example Use Case |
---|---|---|---|
Stack | LIFO (Last-In, First-Out) | Push, Pop, Peek, IsEmpty | Function call stack |
Queue | FIFO (First-In, First-Out) | Enqueue, Dequeue, Peek, IsEmpty | Print queue, task scheduling |
Linked List | Linear sequence of nodes | Insert, Delete, Search, Get | Implementing other ADTs, dynamic lists |
By using ADTs, programmers can write code that is more modular, easier to understand, and more maintainable. The focus on the interface allows for changes to the underlying implementation without affecting the rest of the program.