Till now we've come across many different types of data structures. In this article I'm gonna be talking about a concept called Abstract Data Type.
Primitive Data Types
But before getting started with that, let's first talk about what we exactly mean by "Data types".
So, here's the definition for you - A data type of a variable simply defines what sort of value that variable will contain. Suppose, if it is an "int" type variable it'll contain an integer value, if its a "float" type variable it'll contain a float/decimal value and so on.
Note that - a basic data type also defines the operations it comes associated with. Example - for an "int" variable, the operations allowed on it are Addition, Subtraction, Multiplication, etc. If a variable happens to be of "char" datatype, then we surely cant perform arithmetic operations on it.
User defined Data Types
There's another interesting type of data types that iscalled User defined Data Types. Suppose, if we revisit the concepts of how we define the basic structure of a stack, it looked something like this-
typedef struct stack{
int arr[MAX];
int top;
int size;
}STACK;
As you can see, we've defined the "STACK" data type using the "int" data type. Therefore, this "STACK" data type is an example of UDT or User defined Data Type. The basic definition of UDT is - the data type which is derived from already existing data types.
Abstract Data Types
These data types are called Abstract because the way an operation is performed on this data type is not disclosed. In other words, the implementation of how an operation is performed is abstract, and hence the name "Abstract Data Type".
For example, we know what functions can be performed on a stack - pop, push, isEmpty, isFull, etc.
When a user tries to perform the same functions on a stack, they'll do it easily, no doubt! But they will never know how that operation is being implemented.
So in ADT, we know -
- what data is stored in the structure.
- the functions that can be performed on the structure. But, we don't know -
- How that function is implemented.
Let's take an example to understand it - Suppose you went to the McDonald's and you order your favourite burger. In about 15 minutes your meal was ready, you pay the bill, take your burger and leave.
In this scenario, the abstract thing was how that burger was made. You just asked for it, you paid the bill and you got it. But did you know how it was made?
You didn't! Thats exactly how abstract data types are! You just dont know what's going on in the background, you just know what you gave as input and what you got as output.
Lists, Stacks, Queues, Trees, etc. are all examples of Abstract data types.
The main reason for this implementation process of the functions to be left unknown is that these data structures can be implemented in many different Programming languages. The way of writing the code in all these languages vary. What we can do using structures in C can be done using classes and objects in C++ and might also be done using some other concept in some other programming language.
THE END.
I hope you enjoyed reading this article. This topic looks very confusing if you come across it for the very first time. I've tried my best to include and explain all the knowledge I have, related to this concept. I hope you liked it! You can check out my other posts here.
Happy Learning!