Search Header Logo

Algorithms Quiz

Authored by Amber Fowler

Computers

12th Grade

Used 3+ times

Algorithms Quiz
AI

AI Actions

Add similar questions

Adjust reading levels

Convert to real-world scenario

Translate activity

More...

    Content View

    Student View

25 questions

Show all answers

1.

MULTIPLE CHOICE QUESTION

30 sec • 2 pts

Suppose a large group of people in a room were all born in the same year. Which of the following algorithms will identify the correct people who have the earliest birthday based on just the month and day? For example, a person born on February 10 is considered to have an earlier birthday than a person born on March 5. Which of the three algorithms will identify the correct people?

I. All the people in the room stand up. All standing people form pairs where possible, leaving at most one person not part of a pair. For each pair, the person with the earlier birthday remains standing, while the other person in the pair sits down. If there is a tie, both people sit down. Any individual not part of a pair remains standing. Continue doing this until only one person remains standing. That person has the earliest birthday.

II. All the people in the room stand up. All standing people form pairs with another standing person that they have not previously been paired with where possible, leaving at most one person not part of a pair. For each pair, the person with the earlier birthday remains standing, while the other person in the pair sits down. If there is a tie, both people in the pair remain standing. Any individual not part of a pair remains standing. Continue doing this until only one person remains standing or all persons standing have the same birthday. Anyone still standing has the earliest birthday.

III. Beginning with the number 1, ask if anyone was born on that day of any month. Continue with the numbers 2, 3, and so on until a positive response is received. If only one person responds, that person has the earliest birthday. If more than one person responds, determine which person was born in the earliest month, and that person or those persons have the earliest birthday

I only

II only

I and II

II and III

2.

MULTIPLE CHOICE QUESTION

30 sec • 2 pts

Media Image

Which of the following algorithms displays the correct distance for all possible values of num1 and num2?

Step 1:

Add num1 and num2 and store the result in the variable sum.

 Step 2:    Take the absolute value of sum and display the result.

Step 1:

Subtract num1 from num2 and store the result in the variable diff.

Step 2:

Take the absolute value of diff and display the result.

Step 1:

Take the absolute value of num1 and store it in the variable absNum1.

Step 2:

Take the absolute value of num2 and store it in the variable absNum2.

Step 3:

Add absNum1 and absNum2 and display the result.

Step 1:

Take the absolute value of num1 and store it in the variable absNum1.

Step 2:

Take the absolute value of num2 and store it in the variable absNum2.

Step 3:

Subtract absNum1 from absNum2 and display the result.

3.

MULTIPLE CHOICE QUESTION

30 sec • 2 pts

Media Image

Which of the following algorithms will allow the robot to make a single circuit around the rectangular region of black squares, finishing in the exact location and direction that it started in each of the four grids?

Step 1:

Keep moving forward, one square at a time, until the square  to the right of the robot is black.

Step 2:

Turn right and move one  square forward.

Step 3:

Repeat steps 1 and 2 three more times.

Step 1:

Keep moving forward, one square at a time, until  the square to   the right of the robot is no longer black.

Step 2:

Turn right and move one      square forward.

  Step 3: Repeat steps 1 and 2 three more times.

Step 1:

Move forward three squares.

Step 2:

Turn right and move one square forward.

Step 3: If the square to the right of the robot is black, repeat steps 1 and 2.

Step 1:

Move forward three squares.

Step 2:

Turn right and move one square forward.

Step 3:

If the square to the right of the robot is not black, repeat steps 1 and 2.=

4.

MULTIPLE CHOICE QUESTION

30 sec • 2 pts

Media Image

The code segment below uses the procedure GoalReached, which evaluates to true if the robot is in the gray square and evaluates to false otherwise.

REPEAT UNTIL (GoalReached ())

{

<MISSING CODE>

}

Which of the following replacements for <MISSING CODE> can be used to move the robot to the gray square?

REPEAT UNTIL (CAN_MOVE (forward) = false)

{

ROTATE_RIGHT ()

}

MOVE_FORWARD ()

REPEAT UNTIL (CAN_MOVE (forward) = false)

{

MOVE_FORWARD ()

}

ROTATE_RIGHT ()

REPEAT UNTIL (CAN_MOVE (right))

{

ROTATE_RIGHT ()

}

MOVE_FORWARD ()

REPEAT UNTIL (CAN_MOVE (right))

{

MOVE_FORWARD ()

}

ROTATE_RIGHT ()

5.

MULTIPLE CHOICE QUESTION

30 sec • 2 pts

A programmer is creating an algorithm that will be used to turn on the motor to open the gate in a parking garage. The specifications for the algorithm are as follows.

  • The gate should not open when the time is outside of business hours.

  • The motor should not turn on unless the gate sensor is activated.

  • The motor should not turn on if the gate is already open.

Which of the following algorithms can be used to open the gate under the appropriate conditions?

Check if the time is outside of business hours. If it is, check if the gate sensor is activated. If it is, check if the gate is closed. If it is, turn on the motor.

Check if the time is during business hours. If it is, check if the gate sensor is activated. If it is, check if the gate is open. If it is, turn on the motor.

Check if the time is during business hours. If it is, check if the gate sensor is activated. If it is not, check if the gate is open. If it is not, turn on the motor.

Check if the time is during business hours. If it is, check if the gate sensor is activated. If it is, check if the gate is open. If it is not, turn on the motor.

6.

MULTIPLE CHOICE QUESTION

30 sec • 2 pts

A certain game keeps track of the maximum and minimum scores obtained so far. If num represents the most recent score obtained, which of the following algorithms correctly updates the values of the maximum and the minimum?

If num is greater than the minimum, set the minimum equal to num. Otherwise, if num is greater than the maximum, set the maximum equal to num.

If num is less than the minimum, set the minimum equal to num. Otherwise, if num is greater than the maximum, set the maximum equal to num.

If num is less than the minimum, set the minimum equal to num. Otherwise, if num is less than the maximum, set the maximum equal to num.

If num is greater than the minimum, set the minimum equal to num. Otherwise, if num is less than the maximum, set the maximum equal to num.

7.

MULTIPLE CHOICE QUESTION

30 sec • 2 pts

Three different numbers need to be placed in order from least to greatest. For example, if the numbers are ordered 9, 16, 4, they should be reordered as 4, 9, 16. Which of the following algorithms can be used to place any three numbers in the correct order?

If the first number is greater than the middle number, swap them. Then, if the middle number is greater than the last number, swap them.

If the first number is greater than the middle number, swap them. Then, if the middle number is greater than the last number, swap them.

If the first number is greater than the middle number, swap them. Then, if the last number is greater than the last number, swap them. Then, if the first number is greater than the middle number, swap them.

If the first number is greater than the middle number, swap them. Then, if the middle number is greater than the last number, swap them. Then, if the first number is greater than the middle number, swap them.

Access all questions and much more by creating a free account

Create resources

Host any resource

Get auto-graded reports

Google

Continue with Google

Email

Continue with Email

Classlink

Continue with Classlink

Clever

Continue with Clever

or continue with

Microsoft

Microsoft

Apple

Apple

Others

Others

Already have an account?