An algorithm is a set of steps to solve a problem or produce a specific outcome.

For example, here's a simple algorithm to make ice cubes:

  1. Take out an ice cube tray
  2. Pour water into the ice cube tray
  3. Put the ice cube tray in freezer
  4. Wait for 3 hours until the ice is set
  5. Remove 2 ice cubes from the tray and place it in your cup

Algorithms often involve logic to solve more difficult problems or increase efficiency.

For example, an algorithm to help you decide what to wear based on the weather might use if/else statements like this:

  1. If it is raining outside, wear a rain jacket and take an umbrella
  2. 2. Else if it is hot outside, wear a t-shirt, shorts, and slippers
  3. 3. Else if it is cool outside, wear a sweater and jeans
  4. 4. Else, wear a t-shirt and jeans

Or if you want to make ice cubes more efficiently, you could rewrite the ice cube making algorithm to use if / else statements and a loop like this:

  1. Take out an ice cube tray
  2. Pour water into the ice cube tray
  3. Put the ice cube tray in freezer
  4. Wait 1 hour and check on the ice cubes
  5. If the ice is set, remove 2 ice cubes from the tray and place it in your cup
  6. Else, return to step 4

Algorithms in computer science are often grouped into categories like sort and search. Many algorithms within each category are very well known, and have names like merge sort or binary search.

When choosing an algorithm to use, programmers often compare algorithms based on efficiency. The two main ways to measure an algorithm's efficiency is time complexity and space complexity.

Time complexity is a measure of how long the algorithm takes to run. Space complexity is a measure of how much storage the algorithm needs.

Some algorithms are much more efficient than others, but may need more computer storage space to run. But even the most efficient algorithm may be much slower if there is a lot of data it has to sort or search through.

To quickly summarize the speed or complexity of an algorithm, programmers use Big O notation. You can read more about Big O notation here.