Overview of DSA Problem Solving Techniques

1. Brute Force Technique
- β
Try all possible combinations or solutions.
- π Use when constraints are small (e.g., β€10β΄).
- β οΈ High time complexity; not optimal for large inputs.
2. Greedy Algorithm Technique
- β
Make the locally optimal choice at each step.
- π Use when the problem has the greedy-choice property and optimal substructure.
- β οΈ Doesnβt always guarantee global optimality unless proven.
3. Divide and Conquer
- β
Split the problem into subproblems, solve recursively, then combine.
- π Useful in sorting, searching, matrix operations.
- β οΈ Recursion overhead; must handle base cases carefully.
4. Dynamic Programming (DP)
- β
Break problems into overlapping subproblems with optimal substructure.
- π Use when subproblems repeat (e.g., Fibonacci, Knapsack).
- β οΈ Needs memoization/tabulation and careful state definition.
5. Backtracking
- β
Try all options and undo choices that don't work (recursive).
- π Use in permutations, combinations, constraint satisfaction.
- β οΈ Can be exponential in complexity; pruning is critical.
6. Recursion
- β
Solve problems by solving smaller instances of the same problem.
- π Useful in tree traversal, divide & conquer, DP.
- β οΈ Stack overflow risk for deep recursion; base case required.
7. Sliding Window
- β
Maintain a window to track optimal subarray or substring.
- π Use when working with contiguous sequences (e.g., longest subarray with sum β€ K).
- β οΈ Only works when window movement rules are clear.
8. Two Pointers
- β
Use two indices to traverse from both ends or in sync.
- π Works well in sorted arrays, strings, or when scanning pairs.
- β οΈ Data must allow ordered traversal or merging logic.
9. Binary Search
- β
Divide search space in half to locate the answer efficiently.
- π Use when the array/search space is sorted or monotonic.
- β οΈ Conditions must ensure a strictly increasing/decreasing space.
10. Tree / Graph Traversal
- β
Visit nodes using DFS (depth-first) or BFS (breadth-first).
- π Use for pathfinding, connectivity, tree-based problems.
- β οΈ Must handle cycles (in graphs) and visited states.
11. Bit Manipulation
- β
Use bitwise operators to solve problems efficiently.
- π Useful in toggling, masking, subset generation, XOR tricks.
- β οΈ Requires understanding of binary operations.
12. Hashing Technique
- β
Use hash maps/sets for quick lookups and counting.
- π Best for frequency maps, duplicates, prefix sums, etc.
- β οΈ Hash collisions and memory usage can be concerns.
13. Heaps Technique
- β
Use a min-heap or max-heap for efficient extreme value tracking.
- π Use in priority queues, top-k elements, scheduling problems.
- β οΈ Requires heap property maintenance via insertion/deletion.