In programming, we use so many types of data structures to provide a proper structure to our data. A data structure is basically used to collect and organize the data on which we are going to perform the operations. For example, we all know what is an array, it is one of the most-used data structures.
We use arrays to collect similar data types and organize them in a linear structure. In a programming language, we require different types of data structures in order to make an effective program.
Similar to object-oriented programming , we use a class to store different kinds of data types and functions (methods). There are so many data structures present in the programming world. Here, we are going to discuss them.
Types of Data Structure
Data structures are basically of two broad types:
Primitive Data Structure
Primitive data structures are further classified into the following types:
- (Double) Floating-point Numbers
Non-Primitive Data Structure
We can classify all non-primitive data structures into the following categories:
Linear Data Structure
Non-Linear Data Structure
- File Data Structure
Primitive Data Structure
These types of data structures are the basic data structures and most of these are built-in data structures in many high-level programming languages. Primitive data structures can be defined as data types present in the programming languages. The main property of a primitive data structure is they can not be further divided, they are elementary.
Basic Types of Primitive Data Structure:
- Integer: The integer holds all the integer values, basically all the positive and negative numbers without decimal. e.g. 11
- Floating Points Numbers: Floating point numbers also cover all the real number positive, fractions, as well as negative with the decimal point. E.g. = 11.0
- Character: Character holds every character, may it be any number, alphabets, or any special symbol but it would be represented inside the double or single inverted comma. eg = ’$’
- Pointers: Pointers hold (point to) the memory address of the variables, pointers, etc.
Non-Primitive Data Structures:
Non-primitive data structures are the complex data structures we use in programming. Mostly, all the non-primitive data structures are user-defined data structures, though many languages provide in-built support for these data structures, and, thus they are considered the user-defined data structure.
This type of data structure uses primitive data structures to form a structure, that’s why it’s said that non-primitive data structures are derived from primitive data structures. The main property of a non-primitive data structure is that it can be further divided into primitive data structures.
Types of Non-Primitive Data Structure:
There are 3 types of Non-Primitive Data Structure:
- Linear Data Structure
- Non-Linear Data Structure
- Files Data Structure
1. Linear Data Structure:
In the linear data structure, elements are stored in a sequential manner. Myth-buster, their name doesn't that they store elements in a linear or contiguous memory location.
Types of Linear Data Structure:
The linear data structure is further divided into 4 categories:
- Array: Array is a homogeneous collection of elements. In simple words, an array can store only similar data types at once. An array stores all the elements in a linear sequence and in a contiguous memory location. Due to storing elements in contiguous memory locations, the operation, such as retrieving data elements is very easy. There are many disadvantages of an array, such as it can only store similar data types at once and are not that much memory efficient when it’s come to an arbitrary number of elements.
- List: The functionality of a list is similar to an array. It also stores elements in a linear sequence. List, however, uses dynamic memory allocation to store its elements at different memory locations. Though elements are stored at different memory locations, all are arranged in a sequence and linked with another.
- Stack: Stack is similar to a list but follows the LIFO principle to store and retrieve elements. LIFO stands for Last In First Out, which means the element stored last in the stack would be retrieved first. To perform the LIFO principle, the stack uses two operations push and pop. push() is used to insert an element in the stack, while pop() is used to retrieve one or many.
- Queues: The Queue data structure is just the opposite of the stack since it uses the FIFO principle. FIFO stands for first in first out. In a queue, the element stored first in the structure would be retrieved first.
Non-Linear Data Structure
In a non-linear data structure, the storage of elements doesn't follow a sequential order.
Types of Non-Linear Data Structure
- Graph: Used for network representation. A graph data structure basically uses two components vertices and edges. In the graph, Edges are used to connect vertices.
- Tree: The tree data structure uses a hierarchical form of structure to represent its elements. One of the famous tree data structures is the Binary tree. A tree uses a node-like structure to make a hierarchical form, where each node represents a value. The uppermost node of the tree is known as the root node and the bottom node is known as a leaf node. Tree data structures are the most complex, and efficient, data structures we use in programming. As such, we use these to solve many real-time problems.
File Data Structure
A file is a collection of records. Using a file we can store data in the .txt format. Many programming languages come with a built-in file handling structure. We can perform read, write, and append operations on files, so we could add and retrieve data from them. The file is the easiest method of creating and retrieving data, but it is not productive when it comes to handling a huge amount of data.
Data structures are the most important part of a programming language and during tech interviews, the favorite topic of the interviewer. That's probably because the ability to choose the right data structure is one of the vital skills a programmer should possess. In a big project or furthering development with a project, especially dealing with huge amounts of data, developers who have complete knowledge of all basic data structures and are able to manipulate them in order to make them more efficient, are preferred the most.
People are also reading:
- Difference between Union vs Structure
- What is the Python Data Structure?
- Matrix Multiplication in C
- Difference between List vs Array
- What is Functional Programming?
- What is Structure Programming?
- Data Structures Interview Questions
- What is Data Structure?
- Global vs Local Variables
- What is Structured Programming?