Why Data Structure?
Knowledge about data structures helps you understand the working of each data structure. And, based on that you can select the right data structures for your project.
This helps you write memory and time-efficient code.
What is Data Structure?
A data structure is a storage that is used to store and organize data. It is a way of arranging data on a computer so that it can be accessed and updated efficiently.
Depending on your requirement and project, it is important to choose the right data structure for your project.
Types of Data Structures
Data structures are divided into two categories:
Linear data structure
Non-linear data structure
Let's learn about each type in detail.
Linear data structure
In linear data structures, the elements are arranged in sequence one after the other. Since elements are arranged in a particular order, they are easy to implement. However, when the complexity of the program increases, the linear data structures might not be the best choice because of operational complexities.
Array Data Structure
In an array, elements in memory are arranged in continuous memory. All the elements of an array are of the same type. And, the type of elements that can be stored in the form of arrays is determined by the programming language.
In an array, elements in memory are arranged in continuous memory. All the elements of an array are of the same type. And, the type of elements that can be stored in the form of arrays is determined by the programming language.
Stack Data Structure
In the stack data structure, elements are stored in the LIFO principle. That is, the last element stored in a stack will be removed first.
It works just like a pile of plates where the last plate kept on the pile will be removed first.
Queue Data Structure
Unlike stack, the queue data structure works in the FIFO principle where the first element stored in the queue will be removed first.
It works just like a queue of people at the ticket counter where the first person in the queue will get the ticket first.
Linked List Data Structure
In a linked list data structure, data elements are connected through a series of nodes. And, each node contains the data items and addresses to the next node.
Non-linear data structure:
Unlike linear data structures, elements in non-linear data structures are not in any sequence. Instead, they are arranged in a hierarchical manner where one element will be connected to one or more elements.
Non-linear data structures are further divided into a graph and tree-based data structures.
Graph Data Structure
In the graph data structure, each node is called a vertex and each vertex is connected to other vertices through edges.
Tree Data Structure
Similar to a graph, a tree is also a collection of vertices and edges. However, in the tree data structure, there can only be one edge between two vertices.