What is the Brute force approach?

Hrusikesh Swain
2 min readDec 3, 2022

Let’s understand the Brute force approach to solve a programming problem in the software industry. It's one of the most basic and simplest types of algorithms to approach a problem. Technically someone has to move through each and every possible solution to a problem and find the best solution to resolve the issue.

For e.g. suppose a salesman wants to travel to different cities in a state so how can he know what are the ways he has to follow so that the distance traveled by the salesman can be minimized so for this situation he needs to use brute force algorithm.

Suppose we have created a problem in the form of the above tree so here we start from the root node and iterate through the subsequent child nodes at different levels to find the best approach to resolve the issue at node k.

The time complexity for the Brute force algorithm is like O(mn) So, if we were to search for a string of “n” characters in a string of “m” characters using brute force, it would take us n * m tries.

Pros:
1.
The brute force approach is a guaranteed way to find the correct solution by listing all the possible solutions for the problem.
2. It is mainly used for solving simpler and small problems.
3. The brute force algorithm is a simple and straightforward solution to the problem, generally based on the description of the problem and the definition of the concept involved.

Cons:
1.
Brute force algorithms are slow. This method relies more on compromising the power of a computer system for solving a problem than on a good algorithm design
2. It is an inefficient algorithm as it requires solving each and every state.

🌿 Thank you for reading! If you liked this post and want to support me, you can buy me a coffee here 👇

--

--

Hrusikesh Swain

Tech enthusiast interested in Android ,React, Javascript, Node , AWS etc.