Divide and Conquer

Divide and conquer algorithms are a class of algorithms that solve problems by breaking them down into smaller, more manageable sub-problems, solving each sub-problem independently, and then combining their solutions to solve the original problem.

Here’s a general outline of how divide and conquer algorithms work:

  1. Divide: Split the problem into smaller sub-problems of the same type.

  2. Conquer: Solve each sub-problem recursively. If the sub-problems are small enough, solve them directly.

  3. Combine: Merge the solutions of the sub-problems to form the solution to the original problem.

Example: Adding numbers

# Addition of numbers
3 + 6 + 2 + 4

# Subproblem 1: 3 + 6
3 + 6 is 9

# Subproblem 2: 2 + 4
2 + 4 is 6

# Combine the Subproblems
9 + 6 = 15

Recursion

Recursion is a process in which a function calls itself directly or indirectly to solve a problem. The concept of recursion is a pre-requisite skill for divide and conquer.

Last updated