Skip Top Navigation Bar

Introduction to Algorithms Practice

Recipe Algorithms

Grab a Piece of Paper!

Take your favorite box of brownie mix and look at the recipe on the back of the box. If you don't have a box of brownie mix, you can use another type of mix in your cabinet, or google a recipe.

Often as humans we intuitively know what steps we need to do without them having to be spelled out for us. When asked to beat in three eggs into the recipe, we know that you have to first crack them open, check to be sure that we didn't accidental incorporate a piece of shell, then beat them with a fork or whisk before adding them to the mixture. All these steps that we intuitively accomplish, would need to be spelled out for a computer to accomplish them.

Using AI to Improve Your Algorithms

Ask AI to write an algorithm to make brownies. Your prompt might be: "Write an algorithm as succinctly as possible to make a batch of boxed brownies."

Once you get a result, see if you can get the AI to refine the result. Some questions that might help are:

Be sure to read through the algorithm for yourself and identify where the AI may have gotten things mixed up or incorrect. For example, my flowchart included a step for mixing the batter after the pan was greased, but before deciding whether we wanted cake-like brownies or not.

While AI can be a helpful tool, it needs your supervision and guidance. Always be sure to read through the result and make your own necessary updates to ensure that the final product is correct.

Algorithm: Compute A Student Average

Grab a Piece of Paper!

Consider the following algorithm to calculate a student's average.

Compute An Average Algorithm

  1. Create a variable called sum and set it to 0.
  2. Create a variable called total and set it to 0.
  3. As long as there are grades in the list:
    • Is the grade greater than 0 and less than 100?
      • If yes,
        • add a grade to sum
        • add 1 to total
  4. Create a variable called average and set it to sum divided by total

Algorithm: Compute the Total for a List of Purchased Items

Grab a Piece of Paper!

Consider the following steps for an algorithm to compute the amount due for a list of store purchases.

Re-order The Steps

Order the steps above into an algorithm that will compute the total for a list of purchased items.