Zamil's CSE Directory

data structures and algorithms

Common Algorithm Techniques

Get intuition for core algorithm design strategies used across many problem types.

#dsa#algorithms#divide-and-conquer#greedy#recursion#dynamic-programming
dsa, algorithms, divide-and-conquer, greedy, recursion, dynamic-programming guides

In the previous chapters we focused mostly on structures.

Now we look at algorithm design patterns.

These are repeatable ways to approach many problem types.


Divide and Conquer

Break a problem into smaller subproblems, solve them, then combine results.

This approach powers many efficient algorithms, especially in sorting and search.


Greedy Strategy

Make the best local choice at each step.

Greedy methods can be elegant and fast, but they are correct only for specific problem properties.


Recursion

Recursion means solving a problem by calling the same function on smaller inputs.

It is often a natural fit for trees and divide-and-conquer logic.

graph TD
  A[Problem n] --> B[Problem n-1]
  B --> C[Problem n-2]
  C --> D[Base Case]

A valid base case is essential to avoid infinite recursion.


Dynamic Programming (Conceptual)

Dynamic programming is useful when subproblems overlap.

Main idea:

  • solve each subproblem once
  • store results
  • reuse results instead of recomputing

This often transforms very slow solutions into practical ones.


Choosing a Technique

Technique choice depends on problem structure:

  • independent subproblems: divide and conquer
  • optimal local choices: greedy
  • recursive structure: recursion
  • overlapping subproblems: dynamic programming

This recognition skill is a major part of DSA maturity.


Key Ideas to Remember

  • Algorithm design uses reusable strategy patterns.
  • Divide and conquer breaks then combines.
  • Greedy prioritizes local best choices.
  • Recursion solves smaller versions of the same problem.
  • Dynamic programming caches overlapping subproblems.

What Comes Next

Now we apply these ideas to classic tasks every engineer encounters:

sorting and searching algorithms.