Algorithms are collections of steps to solve a particular problem.
Data structures are named locations used to store and organize data. It's a way of arranging data on a computer so that it can be accessed and updated efficiently.
Depending on the requirement and project, it is important to choose the right data structure for your project. For example, if data is to be stored sequentially in memory, then an Array would be a good fit.
Learning data structures and algorithms allow us to write efficient and optimized computer programs.
What are the Types of Data Structures we have?
Linear DS
Non-Linear DS.
Linear DS
In a linear data structure, elements are arranged in sequence one after the other. This makes the implementation of elements easy.
However, when the complexity of the program increases, this data structure might not be the best choice because of operational complexities.
Examples of Linear DS
Arrays: 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.
Stacks: Stacks are stored in the LIFO principle (Last In, First Out). i.e the last element stored in a stack will be removed first. Just like a pile of plates. You can place one plate on top of the pile, where the last plate kept on the pile will be removed first.
Queue: Unlike a Stack, the queue works in with the FIFO principle (First In, First Out) where the first element stored in the queue will be removed first. Similar to a queue of people at a ticket stand where the first person in the queue gets his/her ticket first.
Linked List: In a linked list, data elements are connected through a series of nodes, with each node containing the data item and a memory address linking to the next node.
Non-Linear DS
Unlike linear data structures, elements in non-linear are not stored sequentially. Instead, they are arranged in a hierarchical manner where one element is connected to one or more elements, like a family tree or a cooperate ladder. Non-linear data structures are further divided into graphs and tree-based data structures.
Examples of Non-Linear DS
Graph DS: In the graph data structure, each node is called a vertex and each vertex is connected to other vertices through edges.
Trees DS: Similar to a graph, a tree is also a collection of vertices and edges. However, in trees, there can only be one edge between two vertices.
Common Tree-Based Data Structure
Binary Tree
Binary Search Tree
AVL Tree
B-Tree
B+ Tree
Red-Black Tree
Why Data Structures?
Knowledge of data structures provides a better way of organizing, maintaining, and storing data efficiently and this helps you write memory and time-efficient code.
Other really good resources you should check out are: