Brute Force
This lesson gives a brief introduction to the brute force paradigm using linear search in an unsorted list.
We'll cover the following
Brute force method
Let’s start off our discussion on algorithms with the most straightforward and exhaustive option—the Brute Force approach to solving a problem. This method requires us to go through all the possibilities to find a solution to the problem we want to solve. For instance, if we have a list of integers and we want to find the minimum, maximum, or a certain element in that list, the Brute Force approach requires us to go through all the elements to find that specific element.
Let’s look at an example that might help you visualize this technique.
Example: linear search
Linear/Sequential Search is a method for finding a target value within a given list. It sequentially checks each element of the list for the target value until a match is found or all the elements have been searched. Linear Search runs in linear time (at its worst) and makes n
comparisons (at most), where n
is the length of the list.
Let’s assume that we are given the following list of unsorted integers.
Level up your interview prep. Join Educative to access 70+ hands-on prep courses.