AAB - So... What about? (Lesson)

So... What About?

The Repeat?

Repeat means to do again.  In step 7 and step 16, the word repeat is used in the instruction.  This is another technique to eliminate the need to write steps multiple times, cutting down on the complexity of the code.  This allows for interpretation by the creator of the peanut butter and jelly sandwich.   How much peanut butter is enough?  How much jelly is enough?  These directions will work for multiple people to achieve their goal of their favorite peanut butter and jelly sandwich.

Steps 3 – 6 are written once for peanut butter.  Steps 12 – 15 are written once for jelly.  Each allows for flexibility and reduction in complexity.   Could these be abstracted into one abstraction?  Absolutely!  We will work on this later in the course.        

Flexibility is a major factor in creating algorithms.  If the solution is adaptable to handle multiple cases, then there is less need for change or alteration of the steps of the solution.  This is a time saving feature.

The Pseudocode?

I know you are thinking that knowing when and how to use abstractions or repeats are not initially obvious.  You are correct, they are not.  Everyone starts at the beginning, with a list of everything that you think has to happen to solve a problem.  So let’s create a list of the steps to write pseudocode.

  1. Write out in short steps all you believe has to happen to solve the problem.
  2. Review and Reflect on your steps and add any forgotten steps.
  3. Review and Reflect on your steps and mark all steps that are similar, different color highlighters work great.
  4. Review and Reflect on the like shaded highlighted steps. Can you make them more similar by taking something out and putting it in another step outside of the similar steps?  If so, take action:
    1. Rewrite creating a unique name for each of the similar groups of steps (now an abstraction) as I did for the open jar or close jar.
    2. Pull the common steps out and put them after the long algorithm with the first line being the common unique name created for the similar steps.
    3. Replace the common steps pulled out with one step containing the unique identifying abstraction name for the steps removed.
    4. Repeat steps I– III above until you have completed for all of the highlighted colors.
  5. Review and reflect on the new algorithm and abstractions. Are there groups of steps that might repeat for flexibility?  If so, take action:
    1. Create the repeat step for areas that will be repeated by adding the question step after the set of steps to repeat
    2. Write the statement Yes, repeat steps a to b until step b – 1 is no longer Yes. The letters a and b stand for the step numbers to repeat.
    3. Repeat steps I – II above until you have completed for all of the highlighted colors.

The Review and Reflect?

This is an integral part of problem solving.  Although there are many ways to solve problems, review and reflection will allow for increase in efficiency and flexibility of your answers.  Computer Science continues to grow and expand as everyone in the industry constantly reviews what is and reflects on what could be.

Note that the process of review and reflect is a cyclical process, until done.

IMAGE CREATED BY GAVS AND USED ACCORDING TO TERMS OF USE.