Algorithms: don't know what 'decision' or 'loop' is

thepapercup

New member
Joined
Sep 7, 2008
Messages
9
Well, I'm only in my math class for half an hour every day and I've hit a bump in the road with my homework.

I'm just not sure what a "decision" or a "loop" is when it comes to algorithms. Could somebody help me out?

I'll type up the problem:

The key steps of an algorithm for filling your car with gas at a self-service pump are out of order. Put these steps in the correct order.

A. Place hose nozzle in gas pipe of car.
B. Turn on pump by lifting lever below hanger.
C. Pay cashier for the amount of gas you pumped.
D. Take nozzle off its hanger on pump.
E. If station requires a deposit before pumping, pay deposit.
F. Squeeze nozzle handle to pump; stops automatically.

Answer: E,D,B,A,F,C

((Here's where I need help))

Is there a decision in the algorithm above? If there is, which step involves the decision? Is there a loop in the algorithm above? If there is, describe the loop.

Hope somebody can help me out soon. >.< It's due tomorrow.
 
Re: Algorithms! Help me. >.<

Could A and B be interchanged? Is that a decision?

I believe that a loop is a series of steps that are repeated, possibly many times.
 
Re: Algorithms! Help me. >.<

Hello Paper Cup:

Well, it looks to me like there should be at least a couple more steps (G and H).

There is no step to reverse step D.

There is no step to reverse step B.

When the gas tank is full, do you leave the nozzle in the car while you go to pay the cashier? I claim that you're not done pumping gas until you've both paid AND returned the nozzle to the pump, but maybe your teacher does it differently. (I'd be curious to kow how many nozzles and ripped-out hoses your teacher has collected over the years. :wink: )

Working with what you've got, then I see no LOOPs.

If a loop is executed while going through the steps in an algorithm, then you would need to see at least one of the steps repeated in the answer.

For example, let's say that President Bush decrees that all people pumping gas must only pump $1 at a time -- and then pay before continuing to pump more -- in order to save gas!

So, the algorithm would require you to execute step C after step F causes the pump to stop at every dollar.

The alogrithm becomes:

E,D,B,A,F,C,F,C,F,C,F,C,F,C,F,C,F,C, ...

Hey! What's going on here?

A very important consideration when creating an alogrithm that contains a loop is the EXIT mechanism. If you don't program a step to get you out of the loop, it will continue forever and ever ... which is exactly what often happens with Windows when your computer stops responding (the developers did not foresee some infinite loop, and the CPU keeps cycling through the same steps in the code, with no way to stop).

Decisions in algorithms arise from conditional statements.

The word IF always indicates a conditional statement.

The conditional step in an algorithm generally takes one of the two following forms:

IF <condition> then <do this>

IF <condition> then <do this> otherwise <do that>

I see one conditional statement in your exercise that requires a decision. Do you see it?

Cheers,

~ Mark :)
 
Re: Algorithms! Help me. >.<

mmm4444bot said:
Hello Paper Cup:

Well, it looks to me like there should be at least a couple more steps (G and H).

There is no step to reverse step D.

There is no step to reverse step B.

When the gas tank is full, do you leave the nozzle in the car while you go to pay the cashier? I claim that you're not done pumping gas until you've both paid AND returned the nozzle to the pump, but maybe your teacher does it differently. (I'd be curious to kow how many nozzles and ripped-out hoses your teacher has collected over the years. :wink: )

Working with what you've got, then I see no LOOPs.

If a loop is executed while going through the steps in an algorithm, then you would need to see at least one of the steps repeated in the answer.

For example, let's say that President Bush decrees that all people pumping gas must only pump $1 at a time -- and then pay before continuing to pump more -- in order to save gas!

So, the algorithm would require you to execute step C after step F causes the pump to stop at every dollar.

The alogrithm becomes:

E,D,B,A,F,C,F,C,F,C,F,C,F,C,F,C,F,C, ...

Hey! What's going on here?

A very important consideration when creating an alogrithm that contains a loop is the EXIT mechanism. If you don't program a step to get you out of the loop, it will continue forever and ever ... which is exactly what often happens with Windows when your computer stops responding (the developers did not foresee some infinite loop, and the CPU keeps cycling through the same steps in the code, with no way to stop).

Decisions in algorithms arise from conditional statements.

The word IF always indicates a conditional statement.

The conditional step in an algorithm generally takes one of the two following forms:

IF <condition> then <do this>

IF <condition> then <do this> otherwise <do that>

I see one conditional statement in your exercise that requires a decision. Do you see it?

Cheers,

~ Mark :)


Oh, you make things so much easier to understand, Mark. Thanks a lot.
If I'm right the decision would be step E.
I think I'll come here a lot more often for help on my math since I won't be in class, but half an hour a day. That's only enough time to get my work. D;

Thanks for helping me finish me homework. I really hate going in without it finished.
~Lori
 
Re: Algorithms! Help me. >.<

Loren said:
Could A and B be interchanged? Is that a decision?

I believe that a loop is a series of steps that are repeated, possibly many times.

I thought A and B should have been interchanged, but I had gotten the answers for the first part of this problem in class since I had gotten the assignment a day late. So I guess the answers are right. -shrugs-
Thanks for the help. =3
 
Re: Algorithms! Help me. >.<

thepapercup said:
Loren said:
Could A and B be interchanged? Is that a decision?

I thought A and B should have been interchanged, but I had gotten the answers ...

< SILLYMODE ON >

The given answer represents the more efficient algorithm as you have the nozzle in one hand with the other hand right there in front of the pump and free to lift the handle before you yank and twist and tug and turn to get the nozzle across the vehicle to the other side because you can never remember on which side of the vehicle the filler cap is located, thus saving you the time of returning to the pump to lift the handle otherwise while also avoiding the risk of entering an infinite loop should the hose tension preclude leaving the nozzle unattended. (Sheesh. :roll: )


< SILLYMODE OFF >
 
Top