Classification of Data Structure

Learn via video course
FREE
View all courses
DSA Problem Solving for Interviews using Java
DSA Problem Solving for Interviews using Java
by Jitender Punia
1000
4.9
Start Learning
DSA Problem Solving for Interviews using Java
DSA Problem Solving for Interviews using Java
by Jitender Punia
1000
4.9
Start Learning
Topics Covered

Overview

The data structures are nothing but a meaningful way of arranging, and storing the data in the computer for efficient utilization and processing depending upon the situation. A primitive data structure can store the value of only one data type. The size of a primitive data structure is known as it can store can only one data type. Examples of the primitive data type are integer, character, boolean, float, double, long, etc. Unlike the primitive data structure, a non-primitive data structure can store the value of more than one data type.

Takeaways

Data types:

  • primitive data structures
  • non-primitive data structures.

Cheatsheet for Classification of Data Structure

Before learning about the classification of data structure, let us first learn about data structures and data types.

Data types are nothing but the classification or categorization of the data items. Data types represent the kind of value and also tell what operations can be performed on a particular data. Various programming languages and various data types. On the other hand, the data structures are nothing but a meaningful way of arranging, and storing the data in the computer for efficient utilization and processing depending upon the situation.

Note: The data structures and data types are often used interchangeably.

Let us now learn about the classification of data structure. The data structure can be classified into two categories namely - primitive data structure and non-primitive data structure.

Refer to the diagram below to see the visual representation of the various data types along with their sizes.

Cheatsheet for classification of data structure

Let us briefly discuss the primitive data structures and non-primitive data structures.

Primitive Data Structure

A primitive data structure can store the value of only one data type. For example, a char data structure (a primitive data structure) can store only characters.

Key features of a primitive data structure:

  • The size of a primitive data structure is known as it can store can only one data type.
  • The primitive data structure will always store some data. It cannot contain the NULL value.
  • Examples of the primitive data type are integer, character, boolean, float, double, long, etc.

Now let us learn about the most commonly used non-primitive data structures along with their examples.

Bool

Bool or boolean is a primitive data structure that can be used to store only two values i.e. True or False. The size of a boolean data type is 1 byte but it only uses 1 bit of the 8 bits(1 byte = 8 bits) to store the value. A bool data type is used when we want to track whether a condition is true or false.

Example:

Python

C++

Java

Byte

A byte is a primitive data structure that is used to store 1-byte variables. The size of a byte data type is 1 byte.

Example: Java

Note: The byte data type is an 8-bit signed two's complement integer.

Char

Character or char is a primitive data type that can be used to store the value of a single character (it can store lower case letters as well as upper case letters). The size of a character data type is 2 bytes.

Example: C++

Java

Int

Integer or int is also a primitive data type that can be used to store the numbers in the range: -2312^{31} to 23112^{31-1} or (2147483648 to 2147483647). The size of a character data type is 4 bytes.

Example: C and C++

Java

Python

Float

A floating-point number or float is a primitive data type that can be used to store fractional numbers. It's range is: 3.4e−038 to 3.4e+038. The size of a character data type is 4 bytes.

Example: C and C++

Java

Python

Note: There are two types of floating numbers. The float32 is a 32-bit number and the float64 is a 64-bit number.

Double

Double is also a primitive data type that can be used to store fractional numbers. Its range is 1.7e−308 to 1.7e+308. The size of a character data type is 8 bytes. We need to add d at the end of the number to denote it as a double number in java.

Example: C and C++

Java

Note: Python does not have an inbuilt double data type.

Long

Long is a primitive data type that can be used to store the numbers in the range: 263-2^{63} to 26312^{63-1}. The size of a long data type is 8 bytes. When we have a number larger than the range of integer then we use the long data type.

Example: C and C++

Java

Short

Short is a primitive data type that can be used to store the numbers in the range: 215-2^{15} to 21512^{15-1}. The size of a short data type is 2 bytes. When we have e smaller number than the range of integer then we can use a short data type as it takes only 2 bytes.

Example: C and C++

Java

Note: In C++, short is equivalent to short int.

Pointer

Pointer can also be referred to as a primitive data type that can be used to store the address of another variable. Pointers can store the address of other primitive and non-primitive data types as well. Pointer is supported by languages like C and C++.

Languages like Java and Python have references as a counterpart of pointers.

Example: C and C++

Note: Pointer takes 8 bytes of memory.

Refer to the table below to find the range and size of the primitive data structure according to a 64-bit compiler.

Data TypeSize in 64-bit compilersRange
Bool1 bytetrue or false
Byte1 byte-128 to 127
Char2 bytes0 to 2^16-1
Int4 bytes-2^31 to 2^31-1
Float4 bytes-3.4E+38 to +3.4E+38
Double8 bytes-1.7E+308 to +1.7E+308
Long8 bytes-2^63 to 2^63-1
Short2 bytes-2^15 to 2^15-1

Non-Primitive Data Structure

Unlike the primitive data structure, a non-primitive data structure can store the value of more than one data type. For example, a list in python can store various data types inside it.

Key features of a primitive data structure:

  • The size of a primitive data structure depends upon the type of data it stores.
  • The primitive data structure will be just initialized without storing any data or value. It can contain the NULL value.
  • Examples of the non-primitive data types are linked lists, stacks, queues, dictionaries, etc.

Now let us learn about the most commonly used non-primitive data structures along with their examples.

Array

An array is a linear collection of values stored at contiguous memory locations. Array stores homogeneous values(similar data type values).

To learn more about the arrays, refer to the article - Arrays in Data Structure.

Lists

A list is used to store one or more objects or data elements. Lists are used in python and java mostly. We can say that lists are similar to arrays.

File

A file is used to access a file from the system. A file is a collection of records.

Linked lists

As the name suggests, a linked list is a sequential collection of data elements connected via links. The data element of a linked list is known as a node which contains two parts namely- the data part and the pointer. The data part contains the actual data and the pointer part contains a pointer that points to the next element of the linked list.

To learn more about the linked lists, refer to the article - Linked Lists in Data Structure.

Stack

Stack in a linear data structure that stores data sequentially based on the Last In First Out (LIFO) manner. So, the data which is inserted first will be removed last. Since the last element inserted is served and removed first, the queue data structure is also known as the Last Come First Served data structure.

To learn more about the stacks, refer to the article - Stacks in Data Structure.

Queue

Queue in a linear data structure that stores data sequentially based on the First In First Out (FIFO) manner. So, the data which is inserted first will be removed from the queue first. Since the first element inserted is served and removed first, the queue data structure is also known as the First Come First Served data structure.

To learn more about the queues, refer to the article - Queues in Data Structure.

Conclusion

  • The data structures are nothing but a meaningful way of arranging, and storing the data in the computer for efficient utilization and processing depending upon the situation.
  • The size of a primitive data structure is known as it can store can only one data type. Examples of the primitive data type are integer, character, boolean, float, double, long, etc.
  • Integer is a primitive data type that can be used to store the numbers in the range: 231-2^{31} to 23112^{31-1}. A float is also a primitive data type that can be used to store fractional numbers.
  • Character can be used to store the value of a single character (it can store lower case letters as well as upper case letters).
  • Pointer can also be referred to as a primitive data type that can be used to store the address of another variable. Pointers can store the address of other primitive and non-primitive data types as well.
  • An array is a linear collection of values stored at contiguous memory locations. A list is used to store one or more objects or data elements.
  • A linked list is a sequential collection of data elements connected via links. The data element of a linked list is known as a node which contains two parts namely- the data part and the pointer.
  • Stack in a linear data structure that stores data sequentially based on the Last In First Out (LIFO) manner. Queue in a linear data structure that stores data sequentially based on the First In First Out (FIFO) manner.

Unlock the Power of Efficient Coding! Join Our Data Structures Courses Today and Transform Your Problem-Solving Abilities.