Brute-Force Algorithms

  • Brute-force algorithms generate every possible answer and select only the valid ones.

  • For example, completing a Canvas Quiz by trying all possible answers until earning full points would be considered a brute-force approach. (Although we do limit the number of attempts to three!)

    canvas quiz.png
  • Another example would be pick all subsets of numbers and see which add up to a given sum.

  • Finally, imagine you are trying to break into your friend’s iPhone by guessing the four-digit passcode. You could systematically try all the passcodes between 0000 and 9999. Unfortunately, that would take an extremely long time if you have to tap on each number with your finger to type the passcode (unless you have something like this).

  • Often, brute force algorithms require exponential time.

  • We can usually improve a brute-force algorithm with heuristics and optimizations, but some algorithms can only be solved by brute-force, unfortunately.

results matching ""

    No results matching ""