Key Concepts

Review core concepts you need to learn to master this subject

Brute Force Algorithms

# pseudocode that prints all divisors of n by brute force define printDivisors, n for all numbers from 1 to n if the number is a divisor of n print the number
  • A brute force algorithm solves a problem through exhaustion: it goes through all possible choices until a solution is found.
  • The time complexity of a brute force algorithm is often proportional to the input size.
  • Brute force algorithms are simple and consistent, but very slow.
Linear Search: Conceptual
Lesson 1 of 2
  1. 1
    Imagine that you are a DJ at a party. The diagram on the right shows your playlist for the event. A party guest wants to know if “Uptown Funk” by Bruno Mars is a song on your playlist. You would …
  2. 2
    Linear search can be used to search for a desired value in a list. It achieves this by examining each of the elements and comparing it with the search element starting with the first element to the…
  3. 3
    Linear search is not considered the most efficient search algorithm, especially for lists of large magnitudes. However, linear search is a great choice if you expect to find the target value at the…
  4. 4
    There are two worst cases for linear search. Case 1: when the target value at the end of the list.
  5. 5
    If this search was used 1000 times on 1000 different lists, some of them would be the best case, some the worst. For most searches, it would be somewhere in between. On average it would be in the…
  6. 6
    Linear search runs in linear time. Its efficiency can be expressed as a linear function, with the number of comparisons to find a target increasing linearly as the size of the list, N, increases. …
  7. 7
    Congratulations! You have learned how linear search works and how to use it to search for values in lists. Let’s review what we learned: * Linear search is a search algorithm that sequentia…

How you'll master it

Stress-test your knowledge with quizzes that help commit syntax to memory

Pro Logo