What is an algorithm?

Algorithms are simply a set of instructions that solve a problem. They can be found and created for everything we do.

For example, given the problem of making a sandwich - a possible algorithm could be:

  1. locate a slice of bread
    • if no bread is found, go buy bread, eat something else or give up
  2. locate some butter
    • if no butter is found, go buy butter, eat something else or give up
  3. locate some peanut butter
    • if no peanut butter is found, go buy peanut butter, eat something else or give up
  4. locate a plate
    • if no plate is found, give up
  5. locate a butter knife
    • if no knife is found, give up
  6. place the slice of bread on the plate
  7. use the knife to scoop a teaspoon-sized blob of butter
  8. using the knife, spread the butter onto the bread, covering the entire slice with the butter

… you get the idea 😬

In programming, an algorithm is a murder on instructions (that’s the collective noun for a group of instructions, look it up 😅) that, when executed, solve a specific problem. We usually want the most efficient algorithm, both in terms of performance - time complexity - as well as resource usage - space complexity.

There are a few established algorithms for common programming problems such as searching, sorting, hashing etc. Here we will discuss as many as we can.

Search Algorithms

Sorting Algorithms

Selection Sort