Backtracking
Competitive Programming/Backtracking.md
A backtracking algorithm begins with an empty solution and extends the solution step by step. The search recursively goes through all different ways how a solution can be constructed. Backtracking algorithms are like problem-solving strategies that help explore different options to find the best solution.
The following is a general outline of how a backtracking algorithm works:
- Choose an initial solution.
- Explore all possible extensions of the current solution.
- If an extension leads to a solution, return that solution.
- If an extension does not lead to a solution, backtrack to the previous solution and try a different extension.
- Repeat steps 2-4 until all possible solutions have been explored.
