Before diving into algorithms, it’s important to first study data structures.
The reason is simple: algorithms are built on top of data structures.
Data structures are concerned with how data is stored in the main memory (RAM) and how it can be accessed, managed, and modified efficiently.
There are two types of data structures which are physical and logical data structures
Structures that define how data is stored in memory (actual representation). Physical data structures are used to build the logical data structures. Array and Linked List can create stack,queues,trees and graphs therefore you have to master them first
- Array → Data stored in a contiguous memory block.
- Linked List → Data stored in nodes connected with pointers.
Structures that define how data elements are logically organized and accessed, independent of memory.
-
Stack → Follows Last-In-First-Out (LIFO).
Elements are arranged in Last In First Out format. Used in browser history,memory management etc
-
Queue → Follows First-In-First-Out (FIFO).
Elements are arranged in First In First Out format Used in order processing systems,BFS algorithm,Call Centers etc
-
Tree → Hierarchical structure (parent–child relationship).
Elements are arranged in levels, starting from a root node and branching into children nodes.
Used in databases, file systems, XML/HTML parsing, and hierarchical data representation. -
Graph → Network of nodes connected by edges.
Elements (called vertices) are connected by edges, which can be directed or undirected.
Used in social networks, transportation systems, recommendation engines, computer networks, and shortest path algorithms.