Computer Science

Computer Science Warmups

Beginner Algorithms Warmup

         

Suppose an algorithm with an input of the list: hand, eye, nose, face.

Step 1. Swap places with the 1st and 4th items on the list.

Step 2. Swap places with the 1st and 2nd items on the list.

Step 3. End.

What will be the list at Step 3?

Step 1. Set Loop=0 \text{Loop} = 0 and Doubler=1. \text{Doubler} = 1.

Step 2. Add 1 to Loop. \text{Loop} .

Step 3. Multiply Doubler \text{Doubler} by two.

Step 4. If Loop<4 \text{Loop} < 4 go to Step 2.

Step 5. End.

What is the value of Doubler \text{Doubler} at Step 5?

Step 1. Set Loop=0 \text{Loop} = 0 and Multiple=0. \text{Multiple} = 0.

Step 2. Add 1 to Loop. \text{Loop} .

Step 3. Add 3 to Multiple. \text{Multiple} .

Step 4. If Loop<100 \text{Loop} < 100 go to Step 2.

Step 5. End.

What is the value of Multiple \text{Multiple} at Step 5?

Suppose a function with an input of the string "ABCDEFG". (A is in the 1st position, B is in the 2nd position, and so on.)

Step 1. Set Loop=0. \text{Loop} = 0 .

Step 2. Add 1 to Loop. \text{Loop} .

Step 3. Swap the letter at position Loop \text{Loop} with the letter at position Loop+2. \text{Loop} + 2 .

Step 4. If Loop<4 \text{Loop} < 4 go to Step 2.

Step 5. End.

What will be the string at Step 5?

Suppose an algorithm with an input of the list: Apple, Banana, Carrot, Dragons.

Step 1. If the 1st item on the list has fewer letters than the 2nd item, swap the items.

Step 2. If the 2nd item on the list has fewer letters than the 4th item, swap the items.

Step 3. If the 2nd item on the list has fewer letters than the 3rd item, swap the items.

Step 4. End.

What will be the list at Step 4?

×

Problem Loading...

Note Loading...

Set Loading...