Loading...

Classification of data structure in Cpp

Introduction:

Data structures are the building blocks of computer programs, allowing us to organize and manipulate data efficiently. In the realm of C++ programming , a language known for its versatility and performance, understanding the classification of data structures is paramount. Here, we will delve deep into the categorization of data structures in C++, equipping you with a thorough understanding of how to choose and implement the right one for your specific programming needs.

The data structures can be classified into two broad categories: primitive and non-primitive data types, further into linear and non-linear data types.

Classification of data structure -

1. Primitive Data Structures

Primitive data structures are one of the kinds of data structures that store data of only one type. They are the fundamental building blocks of data structures. The primitive data structures are the pre-define data structures storing the data of only one data type. Some examples of primitive data types are integer, float, long, double, char, Boolean, short, and byte. The four main types of primitive data structures available in all the programming languages are integer, float, Boolean (true or false) and character.

The programming language already defines primitive data structures, or we can say that they are built-in data types in the programming languages.

2. Non-Primitive Data Structures

The non-primitive data structures is another type of data structure that can store more that one type of data. Non-primitive data structures are derived from primitive data structures, which are the user-defined data structures capable of storing more than one type of data in a contiguous or random memory location. Some examples of non-primitive data types include Array, Linked list, stacks,  queues, trees and graphs.

– Non-Primitive Data Structures

The non-primitive data structures can be further classified into two categories: linear and non-linear data structures.

 - - Linear Data Structures

A linear data structure is one in which the components are stored in a sequential order and are linked to the elements before and after them. That is data is arranged in such a way that one element is adjacent to its previous and the the next element. Because the items are kept in a sequential order, they can be accessed or traversed in a single operation.

Because the elements are progressively ordered in memory, linear data structures are easy to build. An array`s data items are traversed one by one, and you can access one element at a time.

The common examples of linear data structures are: Array, Linked-List, Stack, Queue and Hash-map, etc.

It can be classified into two types:

  • Static Data Structures = These are data structures where the size is allocated at the compile time. The content of the data structure can be modified but without changing the memory space allocated to it. This means their memory size cannot be changed during program execution. Index-based access to elements is fast and efficient since the address of the element is known. For example: Array.
  • Dynamic Data Structures = These are data structures where the size is allocated at the run time. In it the size of structure is not fixed (variable size) and can be modified during run time. Dynamic data structures are designed to facilitate change of data structures in the run time. For example: Linked-List, Stack, Queue.

- - Non-Linear Data Structure

In a non-linear data structure, data is connected to its previous, next and more elements like a complex structure. In simple terms, data is not organized sequentially in such type of data structure. In a non-linear data structure, we can`t traverse all the elements in a single run only.

Examples of non-linear data structures are trees and graphs.