Chapter 1

Answers to Exam Preparation Exercises

1.     The steps keep repeating forever, because there is no way for the algorithm to stop.  (Also, it is a poor algorithm because the last action is lathering -- you wouldn't want to leave the lather in your hair.)  Corrected algorithm:

1)  Wet hair.

2)  Lather.

3)  Rinse.

4)  Repeat steps 2 and 3 once.

3.     Recipe for pound cake:

Preheat oven to 350 degrees.

Line the bottom of a 9-inch tube pan with wax paper. 

Sift 2 3/4 c flour, 3/4 t cream of tartar, 1/2 t soda, 1 1/2 t salt, and 1 3/4 c sugar into a large bowl.

Add 1 c shortening to bowl.

If [BRANCH] using butter, margarine, or lard,

        then add 2/3 c milk to bowl,

        else (for other shortenings) add 1 c minus 2 T of milk

              to bowl. 

Add 1 t vanilla to bowl.

If [BRANCH] mixing with a spoon,

        then [PROCEDURE REFERENCE] see the instructions in the

              introduction to the chapter on cakes,

        else (for electric mixers) beat contents of bowl for 2

              minutes at medium speed, scraping bowl and beaters as

              needed. 

Add 3 eggs plus 1 extra egg yolk to bowl.

Melt 3 squares of unsweetened chocolate and add to mixture in bowl.

Beat mixture in bowl for 1 minute at medium speed.

Pour batter into tube pan.

Put pan in oven and bake it for 1 hour and 10 minutes. 

[PROCEDURE REFERENCE] Perform the test for doneness, described in the introduction to the chapter on cakes.

   [LOOP] Repeat the test once each minute until it shows that the cake is done.

Remove pan from oven, and allow cake to cool for 2 hours. 

[PROCEDURE REFERENCE] Follow the instructions for removing the cake from the pan, given in the introduction to the chapter on cakes. 

Sprinkle powdered sugar over cracks in top of cake just prior to serving.

 

4.     Peripheral devices are: disk drive, magnetic tape drive, printer, CD-ROM Drive, auxiliary storage, terminal and mouse.

6. Questions about means-ends analysis:

a. The starting point, ending point, and the allowable actions.

b. Each of the allowable actions may actually be a subproblem, so that means-ends analysis results in a divide and  conquer design.

7.  One approach to finding a job, using the divide-and-conquer strategy, would be as follows:

Find a job

  Find information on available jobs

        Check newspaper

        Call employment service

  Apply for jobs

        Write resume

        Submit resume to potential employers

        Arrange interviews

        Attend interviews

        Make follow-up calls after promising interviews

 

        Each of these steps could be further subdivided.

Answers to Programming Warm-Up Exercises

1. Algorithm for driving to the airport

Drive east 3 blocks to 32nd Street - repetitive

Turn right - sequential

Drive south 2 miles to Dreamy Draw - repetitive

Drive south on Dreamy Draw 2 Miles - repetitive

Exit from Dreamy Draw to Squaw Peak Parkway - sequential

Drive south on Squaw Peak Parkway 5 Miles - repetitive

Exit from Squaw Peak Parkway to airport - sequential

Follow signs to terminal - procedural

2.     Algorithm to make a peanut butter and jelly sandwich:

Open refrigerator door by pulling on door handle.

Remove bread bag, jelly jar and peanut butter jar from refrigerator.

Place bread bag, jelly jar and peanut butter jar on counter.

Close refrigerator door.

Open bread bag by removing twist-tie.

Remove 2 bread slices from bread bag.

Place 2 bread slices on counter.

Close bread bag using twist-tie.

Open jelly jar by unscrewing lid.

Place jelly jar lid on counter.

Open drawer under counter.

Remove knife from drawer.

Close drawer.

Use knife blade to scoop desired amount of jelly out of jar.

Spread jelly on face-up side of one slice of bread.

Close jelly jar by screwing-on lid.

Open peanut butter jar by unscrewing lid.

Place peanut butter jar lid on counter.

Use knife blade to scoop out desired amount of peanut butter.

Spread peanut butter on face-up side of other slice of bread.

Close peanut butter jar by screwing-on lid.

Place face-up sides of bread slices together so that their edges align.

Open refrigerator door by pulling on door handle.

Place bread bag, jelly jar, and peanut butter jar in refrigerator.

Close refrigerator door.

3. See notes on exercise 1 solution above.