Representation of data structure in memory is known as Abstract Data Type. Abstract data types can be a list, stack, or queue which will be used to represent different data structures in memory.
What is Abstract Data Type ?
An abstract data type is a concept that tells us about the operations and data on which the operations can be performed without showing its actual implementation. The abstract data type provides the concept of abstraction where complex implementation details are hidden from the users.
An abstract data type is a concept that is independent of the implementations, for example, A data structure may have different implementations in a different language.
Therefore by using ADT users can be benefited as the data structures may have different implementations but at least the concept, the features, and the operations are known.
Note :
Abstract data type does not specify how data is stored in the memory area.
For Example :
If the laptop is an ADT and it can perform various operations like browsing, playing games, chatting, etc. but we don’t know how these functions work in the backend means we don’t know the implementation but knows the features.
We can think of abstract data type as a gaming console where we are allowed to play games without even bothering about how games are running which means the gaming console hides the inner structure and implementation from the user.
An ADT can be implemented in multiple ways, for example, a stack ADT can be implemented using both arrays and linked lists where the stack data structure is implemented using other data structures.
Types of ADT :
There are mainly three types of abstract data type(ADT) :
- List ADT
- Stack ADT
- Queue ADT
Let us discuss them.
List ADT
A list is a linear data structure that is used to store a collection of ” similar types of data”. The list ADT is an ordered collection of data which is stored sequentially inside the list and the data have a linear relationship with each other.
A list is a common real-world entity that can be implemented by using dynamic arrays or linked lists where the list has data and certain operations that can be performed on the data without the implementation details.
There are certain operations that are performed on the list which are as follows :
- isEmpty() : To check whether list is empty or not.
- isFull() : To check whether list is full or not.
- traverse() : Visit every element stored in the list.
- insert() : Insert element in the list.
- delete() : Delete element from the list.
- size() : Gives size of the list.
Stack ADT
Stack is a linear data structure that allows the addition and deletion of elements in a particular order. Stack ADT follows LIFO(Last In First Out) or FILO(First In Last Out) order. It is an abstract data type with a bounded or predefined capacity.
Stack ADT behaves like a real-world stack, for example, a stack of books, a stack of plates, etc. which allows operations at one end only. Stack ADT can be implemented using arrays and linked list which has data like top pointer and elements to be inserted. Operations on stack ADT is carried out easily with the help of the top pointer.
There are some common operations that are performed on the stack which are as follows :
- push() : Inserting element at top of the stack.
- pop() : Deleting element from the top of the stack.
- isEmpty() : Checking whether stack is empty or not.
- isFull() : Checking whether stack is full or not.
- peek() : Fetch value from particular position of stack.
- count() : Gives number of elements in the stack.
- stackTop() : Gives top element of the stack.
To learn more in-depth concepts of stack data structure visit Stacks.
Queue ADT
A queue is a linear data structure that allows the addition of elements from one end which is the rear end and the deletion of elements from another end which is the front end. The addition and deletion of elements are called Enqueue and Dequeue respectively.
Queue ADT follows FIFO(First In First Out) or LILO(Last In Last Out) order. Unlike stack ADT, a queue is a kind of abstract data type which allows operations from both ends. It is called a queue because it behaves like a queue in real life.
for example, a queue of bikes in traffic, a queue of persons standing for a movie ticket, etc. in which whoever comes first, will get the service first. A queue can be used where we want to fetch the elements in the order of insertion. Queue ADT can be implemented by using stacks, arrays, and linked lists.
There are some common operations performed on the queue which are as follows :
- enqueue() : Insert element in the queue.
- dequeue() : Delete element from the queue.
- isFull() : Check whether queue is full or not.
- isEmpty() : Check whether queue is empty or not.
- count() : Count elements in the queue.
Abstract Data Type Model
Abstract data type model contains an application program and an abstracted entity that has data structures and functions bound with each other. So basically this model explains that the application program can use the abstracted entity as an interface through which the program can use data structures.
Even if the application program changes then also it can use the abstract data type model as an interface to interact with the data structures.
An abstract data type is considered a combination of encapsulation and abstraction.
Let us understand a bit about encapsulation and abstraction :
- Encapsulation :
It is the process of binding data and data members or functions inside a single entity. - Abstraction :
It is a concept in which functionality is shown but implementation details are hidden from the users.
So, the ADT model consists of two types of functions that is a private function and a public function which is bound with the data structures in a single unit(abstract data type) which is called encapsulation.
Then abstraction is performed as we can use the functionality of the data structures without bothering about the backend implementations.
Abstract Data Type with a Real-World Example
Let us take a real-world example to understand abstract data type in detail :
Suppose considering a Laptop that has specifications like :
- 14-inch IPS LCD screen, Windows 11 OS, 8 GB Ram, 256 GB SSD, HD Webcam.
Following are the functionalities it can perform :
- browsing(), playGame(), videoConference(), webChating().
Here, we have taken Laptop as an entity that has some specifications or data on which some functionalities can be performed.
Code :
class Laptop
{
private:
float screenSize;
string operatingSystem;
int ram;
int memorySize;
string cameraSpecs;
public:
void browsing();
void playGame();
void videoConference();
void webChating();
};
Above is the real-life implementation of functionalities and specifications that can be performed on the Laptop. Laptops can be different but the functionalities performed by any laptop will be the same.
The implementation of code may be different due to the syntax of different programming languages but the logical view of the data structure will be the same across programming languages.
This shows that an ADT is a concept that is independent of implementations.
Learn More
To learn more about stack data structures and their implementation visit Stacks.
Conclusion
- Representation of data structure in memory is known as Abstract Data Type.
- Abstract data type is a concept that tells about operations and data on which operations can be performed without knowing the implementation details.
- There are three types of ADT:
- List ADT
- Stack ADT
- Queue ADT
- Abstract data type model is a combination of encapsulation and abstraction.
Ready to Build Strong Foundations? Enroll Now in Our Data Structures and Algorithms Course for Coding Excellence!