Javatpoint Logo
Javatpoint Logo

Data types vs data structure

What is a data type?

The two things we must know about the data types are:

  • It defines a certain domain of values.
  • It defines operations allowed on those values.

For example:

If the data is of int (integer) type

Then it takes only integer values

Operations that can be performed on the data type are addition, subtraction, multiplication, bitwise operations, etc.

If the data is of float (floating) type

Then it takes only floating type values.

Operations that can be performed on the data type are addition, subtraction, multiplication, division, etc. (bitwise and % operations are not allowed).

So, it is cleared from the above examples that data type does not only define a certain domain of values but also defines operations that can be performed on those values.

User-defined data type

In contrast to primitive data types, there is a concept of user-defined data types. The values and the operations that can be performed on the primitive data types are not specified by the language itself, but it is specified by the user only. The examples of user-defined data types are structure, union, and enumeration. By using the structures, we can define our own type by combining other primitive data types. Let's understand through an example.

In the above code, we have created a user-defined data type named 'point' that is made by combining two primitive data types of integer type named 'x' and 'y'.

Abstract data types

Abstract data types are like user-defined data types, which define the operations on the values using functions without specifying what is inside the function and how the operations are performed.

For example:

Stack ADT: Here, the stack consists of elements of the same type arranged in sequential order. The following are the operations that can be performed on the stack are:

  • initialize(): This method initializes the stack to be empty.
  • push(): It is a method used for inserting an element into the stack.
  • pop(): It is a method used for removing the element from the stack.
  • isEmpty(): This method is used to check whether the stack is empty or not.
  • isfull(): It checks whether the stack is full or not.

Note: We can think of ADT as a black box that hides the user's inner structure and design of the data type.

There are multiple ways to implement an ADT. For example, a stack ADT can be implemented using arrays or linked lists.

Why ADT?

The program which uses data structure is known as a client program, and it has access to the ADT or interface. The program that implements the data structure is known as implementation.

Advantage

If someone wants to use the stack in the program, he can directly use the push and pop operations in the program without knowing its implementation details.

What is data structure?

A Data structure is a collection of different types of data on which a specific set of operations can be performed. It is a collection of different data types. It is a way of organizing the data in memory. The various operations that can be performed on a data structure are insertion, deletion, and traversal. For example, if we want to store the data of many students where each student has a student name, student id, and a mobile number. To store such big data requires complex data management, which requires a data structure comprising multiple primitive data types.

Differences between the data type and the data structure

Data types vs data structure
Data type Data structure
A Data type is one of the forms of a variable to which the value can be assigned of a given type only. This value can be used throughout the program. A Data structure is a collection of data of different data types. This collection of data can be represented using an object and can be used throughout the program.
The implementation of data type is known as an abstract implementation. The implementation of data structure is known as a concrete implementation.
It can hold value but not data. Therefore, we can say that it is data-less. It can hold multiple types of data within a single object.
In case of data type, a value can be assigned directly to the variables. In the case of data structure, some operations are used to assign the data to the data structure object.
`There is no problem in the time complexity. When we deal with a data structure object, time complexity plays an important role.
The examples of data type are int, float, char. The examples of data structure are stack, queue, tree, graph.






Youtube For Videos Join Our Youtube Channel: Join Now

Feedback


Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA