In this journey of learning data structures, we will learn about data types and abstract data types.
Table of Contents
ToggleData Type
A data type means the kind of category of data that tells a computer what types of value is being stored and how much memory it needs.
Example: int, float, char, short, long, string, double etc.
Important Things about data types:
- Define a certain domain of values.
- Defines Operation allowed on those values.
Example 1:
int type
Taking Only integer values
Operations: addition, subraction, multiplication, bitwise operation etc.
We can easily perform addition, subtraction, multiplication, and bitwise operations on integer data types.
Example 2:
float type
Taking Only floating point values
Operations: addition, subraction, multiplication, division etc (bitwise and % operation are not allowed).
In floating point data type we can do addition, subtraction, multiplication, division but we cannot do bitwise operations and modulation (%) operations.
User Define Data Type
In contrast to primitive data types, there is a concept of user define data types.
The operations and values of user defined data types are not specified in the language itself but is specified by the user.
Example:- Structure, Union and Enumeration
By using structure, we are defining our own type by combining other data types.
struct point{
int x;
int y;
};
Abstract Data Type (ADT)
ADTs are like user defined data types which defines operations on values using functions without specifying what is there inside the function and how the operations are performed.
Example: Stack ADT
A stack consists of elements of same type arranged in a sequential order.
Operation:
initialize() - initializing it to be empty
Push() - Insert an element into the stack
Pop() - Delete an element from the stack
isEmpty() - checks if stack is empty
isFull() - checks if stack is full
Think of ADT as a black box which hides the inner structure and design of the data type from the user.
There are multiple ways to implement an ADT.
Example:-
A stack ADT can be implemented using arrays of linked lists.
Why ADT?
The program which uses data structure is called a client program.
It has access to the ADT i.e. interface.
The program which implements the data structure is known as the implementation.
Advantage
- Let say, if someone wants to use the stack in the program, then he can simply use push and pop operations without knowing its implementation.
- Also, if in future, the implementation of stack is changed from array to linked list, then the client program will work in the same way without being affected.
