


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. The time complexity of brute force is O(mn ), which is sometimes written as O(n*m). This is not particularly efficient because it is possible to eliminate many possible routes through clever algorithms. The brute force solution is simply to calculate the total distance for every possible route and then select the shortest one. How does one determine the order in which those cities should be visited such that the total distance traveled is minimized? Suppose a salesman needs to visit 10 cities across the country. In the worst case scenario, it would take 10 4, or 10,000 tries to find your combination.Ī classic example in computer science is the traveling salesman problem (TSP). So you set all the numbers back to 0 and try them one by one: 0001, 0002, 0003, and so on until it opens. Since you can't remember any of the digits, you have to use a brute force method to open the lock. You forgot your combination, but you don't want to buy another padlock. 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.įor example, imagine you have a small padlock with 4 digits, each from 0-9.
