Recipe Algorithms
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.
- Identify the decisions that need to be made.
- Identify any repetition in the recipe.
- Re-write the recipe as a pseudocode version of the algorithm.
- Re-write the recipe as a flowchart version of the algorithm.
Which representation of the recipe is your favorite and why?
Bonus: Make the brownies (or other recipe you choose).
- Are there any hidden steps that you did automatically?
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:
- Modify the algorithm to include the decisions for whether you want cake like brownies or not.
- Modify the algorithm to include a decision around teh size pan you want to use.
- Identify where repetition happens in the algorithm.
- Represent the algorithm as a flowchart.
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.
Ordering Algorithms
Compute A Student Average
Consider the following algorithm to calculate a student's average.
- Create a variable called sum and set it to 0.
- Create a variable called total and set it to 0.
- 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
- Create a variable called average and set it to sum divided by total
- Identify where the decision is in the algorithm.
- Identify where the repetition is in the algorithm.
- Write a flowchart to reflect this algorithm.
Compute the Total for a List of Purchased Items
Consider the following steps for an algorithm to compute the amount due for a list of store purchases.
- Access the price of the item to the list.
- Access the quantity of how many of an item is being purchased.
- Create a variable called total and set it to 0.
- Compute the total by adding the subtotal and taxrate and assigning total this result.
- Create a variable called subtotal and set it to 0.
- Add the price of the item times the quantity being purchased to the subtotal and assign this new value to subtotal.
- Repeat for all items in the purchase list.
- Create a variable called taxrate and set it to the subtotal times the 0.06.
Order the steps above into an algorithm that will compute the total for a list of purchased items.