Brute Force Algorithm

Vijay Karthik N
3 min readApr 10, 2022

Brute force algorithm is a straightforward approach that is usually based on problem statement and definitions

1. Computing an 1. Computing a (a > 0 n a nonnegative integer)

2. Computing n!

3. Multiply two Multiply two n by n matrices

4. Selection sort

5. Sequential search

Brute-Force Sorting Algorithm

Selection Sort: Scan the array to find its smallest element and swap it with the first element. Then, starting with the second element, scan the elements to the right of it to find the smallest among them and swap it with the second the smallest among them and swap it with the second elements.

Generally, on pass i (0 i n-2), find the smallest element in smallest element in A[i..n-1] and swap it with 1] and swap it with A[i]:

A[0] . . . A[i-1] | A[i], . . . , A[min], . . ., A[n-1] in their final positions.

Efficiency

Algorithms are most commonly judged by their efficiency and the amount of computing resources they require to complete their task.

A common way to evaluate an algorithm is to look at its time complexity. This shows how the running time of the algorithm grows as the input size grows. Since the algorithms today have to operate on large data inputs, it is essential for our algorithms to have a reasonably fast running time.

Brute Force Algorithms are exactly what they sound like — straightforward methods of solving a problem that rely on sheer computing power and trying every possibility rather than advanced techniques to improve efficiency.

Brute force search considers each and every state of a tree, and the state is represented in the form of a node. As far as the starting position is concerned, we have two choices, i.e., A state and B state. We can either generate state A or state B. In the case of B state, we have two states, i.e., state E and F.

In the case of brute force search, each state is considered one by one. As we can observe in the above tree that the brute force search takes 12 steps to find the solution.

Advantages of a brute-force algorithm

The following are the advantages of the brute-force algorithm:

  • This algorithm finds all the possible solutions, and it also guarantees that it finds the correct solution to a problem.
  • This type of algorithm is applicable to a wide range of domains.
  • It is mainly used for solving simpler and small problems.
  • It can be considered a comparison benchmark to solve a simple problem and does not require any particular domain knowledge.

Disadvantages of a brute-force algorithm

The following are the disadvantages of the brute-force algorithm:

  • It is an inefficient algorithm as it requires solving each and every state.
  • It is a very slow algorithm to find the correct solution as it solves each state without considering whether the solution is feasible or not.
  • The brute force algorithm is neither constructive nor creative as compared to other algorithms.

--

--