Correct Solutions to the Shampooing Problem

Straight Through Steps

  1. Wet your hair
  2. Lather your hair
  3. Rinse your hair
  4. Lather your hair
  5. Rinse your hair
  6. Stop

Repeated Step Operation

  1. Wet your hair
  2. Set the value of WashCount to 0
  3. Repeat steps 4 through 6 until the value of WashCount equals 2
  4.     Lather your hair
  5.     Rinse your hair
  6.     Add 1 to the value of WashCount
  7. Stop

Conditional Step Operation

  1. Wet your hair
  2. Hair is dirty
  3. Repeat steps 4 through 6 until Hair is clean
  4.     Lather your hair
  5.     Rinse your hair
  6.     Check Hair for cleanliness
  7. Stop

Are these EQUIVALENT algorithms?

[TOC]

CS1104 Main Page
Last Updated 2002/01/18
© L.Heath & J.A.N. Lee, 2000-2002.