what is brute force algorithm
Quick Scoop: A brute force algorithm solves a problem by trying every possible option until it finds the correct one. It is simple and reliable, but often slow for large inputs because the number of possibilities can grow very fast.
What it means
Brute force is a direct, exhaustive approach : instead of using a clever shortcut, it checks candidates one by one until one works or all are tested. It is often used when the input is small, when correctness matters more than speed, or when no better method is known.
Example
If you forgot a 4-digit lock code, a brute force method would try every code
from 0000 to 9999 until the lock opens. That works, but it can take a lot
of attempts if the search space is large.
Pros and cons
| Pros | Cons |
|---|---|
| Easy to understand and implement | Often very slow for large problems |
| Guaranteed to find a solution if one exists and all possibilities are checked | Can become impractical as the number of possibilities grows |
Where it is used
Brute force is common in simple search problems, string matching, small optimization tasks, and as a baseline for comparing faster algorithms. It is also associated with password-guessing or key-guessing attacks in security contexts, where every possible key is tried.
TL;DR: brute force means try everything until it works —easy to code, but usually inefficient for big problems.