Common DSA Patterns
1. Sliding Window
Used to solve problems involving subarrays or substrings. It involves a window which slides over the
data structure to examine a subset of elements.
2. Two Pointers
Commonly used with sorted arrays or linked lists to find pairs that satisfy a certain condition.
3. Fast and Slow Pointers
Used for cycle detection in linked lists or arrays, and for finding the middle of a linked list.
4. Merge Intervals
Used for problems that require overlapping intervals to be merged or processed together.
5. Cyclic Sort
Used when the input array contains numbers in a given range. Helps to sort with constant space.
6. In-place Reversal of a Linked List
Pattern to reverse a linked list or a sublist in-place with constant space.
7. Tree BFS/DFS
Traverse tree or graph level by level (BFS) or depth-wise (DFS). Used in many graph and tree
problems.
8. Topological Sort
Used for scheduling tasks or ordering of nodes in a directed acyclic graph (DAG).
9. Backtracking
Used to explore all possibilities and backtrack once a solution path fails. Useful in constraint
satisfaction problems like Sudoku or N-Queens.
10. Dynamic Programming
Used to solve problems by breaking them down into simpler subproblems and storing results to
avoid redundant computation.