Deep breathe with “Brute force” algorithms .

Mohamed Zead
Take a deep breathe with algorithms .
3 min readJun 22, 2019

What are algorithms and why to learn ?

You can consider algorithm as any steps you apply to solve any problem you face in your work , homework or even in your strategic computer games .

Why we learn it ? as a person related to tech you should know that algorithms topic is the core of computer science . You probably dealt with arrays , sets , linked lists or any kind of “Data Structures “ , these well known algorithms help you and simplify the operations you make on this structure like sorting , searching , deleting ..etc

First Approach and well known one is the brute force strategy , brute force meaning is that algorithm try to find the solution even if it takes the worst case scenario not considering space and time factors meaning that it’s not the optimal solution .

Other definition : Brute Force Algorithms refers to a programming style that does not include any shortcuts to improve performance, but instead relies on sheer computing power to try all possibilities until the solution to a problem is found.

Sequential search algorithm :

This is the simplest search algorithm that you often use in small collections of data by looping in sequential order until you find your solution and it’s O(n).

How it works ?

sequential search algorithm
Sequential seach pseudo code

Brute force String matching algorithm :

An algorithm that take a full String of length n and another pattern of String of length m where (m < n) to search if The String contains the pattern or not and it’s O(nm)

How it works ?

String matching algorithm
Brute force string matching pseudo code

Selection Sort Algorithm :

A sorting algorithm through searching the entire array and compare it with the current element and swap between it and smaller or larger element (based on your design ascending or descending order) until collection completely sorted . its O(n²).

How it works ?

Selection sort algorithm

There are a lot of brute force algorithms out there but you should now understand the way brute force strategy works “by trying all the possibilities and force strategy”

And here is a list of brute force strategy algorithms which related to another data structure like tree (DFS , BFS):

Advantages and Drawbacks of Brute force strategy :

  • really handy and easy (not complex )
  • Some of the brute force algorithms are very slow and rаrеlу уіеld efficient algorithms .

Good choice for small projects but not for large scale projects ,imagine you are looping through millions of items .

--

--