APCSP Big Idea 3
Consider the following program. Which of the following expressions represents the value stored in the variable x as a result of executing the program?
2 * 3 * 3 * 3 * 3
Consider the following program, which uses the variables start, end, and current. What is displayed as a result of executing the program?
3 4
A flowchart is a way to visually represent an algorithm. The flowchart below is used by an apartment rental Web site to set the variable to for apartments that meet certain criteria. Which of the following statements is equivalent to the algorithm in the flowchart?
include = (floor > 10) OR (bedrooms = 3)
Consider the following spinner, which is used to determine how pieces are to be moved on a game board. The region labeled "Move 1 space" is six times as large as each of the other two regions. Which of the following code segments can be used to simulate the behavior of the spinner?
spin = RANDOM(1, 8) IF spin = 1 DISPLAY "Lose a turn" ELSE IF spin = 2 DISPLAY "Move 2 spaces" ELSE DISPLAY "Move 1 space"
Which of the following code segments can be used to interchange the values of the variables num1 and num2 ?
temp = num1 num1 = num2 num2 = temp
The code segment below is intended to display all multiples of 5 between the values start and end, inclusive. For example, if start has the value 35 and end has the value 50, the code segment should display the values 35, 40, 45, and 50. Assume that start and end are multiples of 5 and that start is less than end. Which of the following could replace <MISSING EXPRESSION> in line 2 so that the code segment works as intended? Responses
((end - start) / 5) + 1
Consider the following code segment. Which of the following CANNOT be displayed as a result of executing the code segment?
1 3 2 4
Consider the following code segment. What is displayed as a result of executing the code segment?
100 300 500
A game is played by moving a game piece left or right along a horizontal game board. The board consists of spaces of various colors, as shown. The circle represents the initial location of the game piece. The following algorithm indicates how the game is played. The game continues until the game is either won by landing on the red space or lost when the piece moves off either end of the board. If a game is begun by placing the game piece on the rightmost black space for step 1, what will be the value of the counter at the end of the game?
4
The diagram below shows a circuit composed of three logic gates. Each gate takes two inputs and produces a single output. For which of the following input values will the circuit have an output of true ?
A = false, B = true, C = true, D = true
Which of the following is a benefit of using a simulation instead of an experiment to make a prediction? Select two answers.
A simulation allows investigation of a phenomenon without the real-world limitations on time, safety, or budget. A simulation can be used to model real-world events that are impractical for experiments.
Flight simulation software, which imitates the experience of flying, is often used to train airline pilots. Which of the following is LEAST likely to be an advantage of using flight simulation software for this purpose?
Flight simulation software provides a more realistic experience for pilots than actual training flights.
The program segment below is intended to move a robot in a grid to a gray square. The program segment uses the procedure GoalReached, which evaluates to true if the robot is in the gray square and evaluates to false otherwise. The robot in each grid is represented as a triangle and is initially facing left. The robot can move into a white or gray square but cannot move into a black region. For which of the following grids does the program NOT correctly move the robot to the gray square?
Gray / White / White Black / White/ Black White / White / Black White / Black / Black White / White / Start
The following spinner is used in a game. The region labeled "blue" represents 14 of the spinner. The regions labeled "orange" and "purple" are equal in size. Which of the following code segments can be used to simulate the behavior of the spinner? Select two answers.
IF RANDOM (1, 4) = 1 DISPLAY "blue" ELSE IF RANDOM (1, 2) = 1 DISPLAY "orange" ELSE DISPLAY "purple" spin = RANDOM (1, 4) IF spin = 1 DISPLAY "blue" ELSE spin = RANDOM(1, 2) IF spin = 2 DISPLAY "orange" ELSE DISPLAY "purple"
The cost of a customer's electricity bill is based on the number of units of electricity the customer uses. For the first 25 units of electricity, the cost is $5 per unit. For units of electricity after the first 25, the cost is $7 per unit. Which of the following code segments correctly sets the value of the variable cost to the cost, in dollars, of using numUnits units of electricity?
IF numUnits <= 25 cost = numUnits * 5 ELSE cost = 25 * 7 + (numUnits - 25) * 5
In a certain game, the integer variable bonus is assigned a value based on the value of the integer variable score. If score is greater than 100, bonus is assigned a value that is 10 times score. If score is between 50 and 100 inclusive, bonus is assigned the value of score. If score is less than 50, bonus is assigned a value of 0. Which of the following code segments assigns bonus correctly for all possible integer values of score ? Select two answers.
IF(score > 100) { bonus ← score * 10 } ELSE { IF(score ≥ 50) { bonus ← score } ELSE { bonus ← 0 } } IF(score < 50) { bonus ← 0 } ELSE { IF(score > 100) { bonus ← score * 10 } ELSE { bonus ← score } }
A numeric test score is to be converted to a letter grade of A, B, or C according to the following rules: A score greater than 90 is considered an A; a score between 80 and 90, inclusive, is considered a B; and any other score is considered a C. Which of the following code segments will assign the correct letter grade to grade based on the value of the variable score ?
II and III only
Suppose a large group of people in a room were all born in the same year. Consider the following three algorithms, which are each intended to identify the people in the room 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?
II only 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.
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 less than the minimum, set the minimum equal to num. Otherwise, if num is greater than the maximum, set the maximum equal to num.
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. Then, if the first number is greater than the middle number, swap them.
A programmer has a need to round many numeric values to the nearest integer. Which of the following best explains the benefit of using a list as a data abstraction in this situation?
Keeping the numeric values in a list makes it easier to apply the same computation to every data element.
Which of the following is a benefit of using a list as a data abstraction in a program?
Lists often allow their size to be easily updated to hold as many data values as needed.
The following grid contains a robot represented as a triangle, which is initially in the bottom-left square of the grid and facing the top of the grid. The robot can move into a white or a gray square but cannot move into a black region. The following code segment implements an algorithm that moves the robot from its initial position to the gray square and facing the top of the grid. When the robot reaches the gray square, it turns around and faces the bottom of the grid. Which of the following changes, if any, should be made to the code segment to move the robot back to its original position in the bottom-left square of the grid and facing toward the bottom of the grid?
No change is needed; the algorithm is correct as is.
Which of the following are benefits of procedural abstraction? Select two answers.
Procedural abstraction makes it easier for people to read computer programs. Procedural abstraction provides an opportunity to give a name to a block of code that describes the purpose of the code block.
The grid below contains a robot represented as a triangle, initially facing right. The robot can move into a white or gray square but cannot move into a black region. 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) { MOVE_FORWARD () } ROTATE_RIGHT ()
Which of the following are ways in which a programmer can use abstraction to manage the complexity of a program? Select two answers.
Replacing each instance of repeated code with a call to a procedure Replacing several lines of documentation with a single line of documentation name1, name2, name3, and name4 with a list of strings called names
A teacher has a goal of displaying the names of 2 students selected at random from a group of 30 students in a classroom. Any possible pair of students should be equally likely to be selected. Which of the following algorithms can be used to accomplish the teacher's goal?
Step 1: Assign each student a unique integer from 1 to 30. Step 2: Generate a random integer n from 1 to 30. Step 3: Select the student who is currently assigned integer n and display the student's name. Step 4: The student who was selected in the previous step is assigned 0. All other students are reassigned a unique integer from 1 to 29. Step 5: Generate a new random integer n from 1 to 29. Step 6: Select the student who is currently assigned integer n and display the student's name.
The figure below shows four grids, each containing a robot represented as a triangle. The robot cannot move to a black square or move beyond the edge of the grid. 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 no longer black. Step 2: Turn right and move one square forward. Step 3: Repeat steps 1 and 2 three more times.
A student is creating an algorithm to display the distance between the numbers num1 and num2 on a number line. The following table shows the distance for several different values. Which of the following algorithms displays the correct distance for all possible values of num1 and num2 ?
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.
The following algorithm is intended to determine the average height, in centimeters, of a group of people in a room. Each person has a card, a pencil, and an eraser. Step 2 of the algorithm is missing. Which of the following can be used as step 2 so that the algorithm works as intended?
Step 2: Each person writes their height, in centimeters, at the top of the card and writes the number 1 at the bottom of the card.
A list of numbers has n elements, indexed from 1 to n. The following algorithm is intended to display true if the value target appears in the list more than once and to display false otherwise. The algorithm uses the variables position and count. Steps 4 and 5 are missing. Step 1:Set count to 0 and position to 1. Step 2:If the value of the element at index position is equal to target, increase the value of count by 1. Step 3:Increase the value of position by 1. Step 4:(missing step) Step 5:(missing step) Which of the following could be used to replace steps 4 and 5 so that the algorithm works as intended?
Step 4 Repeat steps 2 and 3 until the value of position is greater than n. Step 5 If count is greater than or equal to 2, display true. Otherwise, display false.
Consider the following code segment with integer variables x and y. If x has a value of 7 and y has a value of 20, what is displayed as a result of executing the code segment?
THREE
A graphic artist uses a program to draw geometric shapes in a given pattern. The program uses an algorithm that draws the shapes based on input from the artist. The table shows the approximate number of steps the algorithm takes to draw different numbers of shapes. Based on the values in the table, which of the following best characterizes the algorithm for drawing n shapes, where n is a very large number?
The algorithm runs in a reasonable amount of time because it will use approximately n^2 steps to draw n shapes.
A school library allows students to borrow laptops. A computer program is used to count the number of times a particular laptop has been borrowed from the library (borrows) and the number of times the same laptop has been returned to the library (returns). Which of the following indicate that a particular laptop is not currently borrowed? Select two answers.
The difference between borrows and returns is zero. The sum of borrows and returns is a positive even number.
A certain computer game is played between a human player and a computer-controlled player. Every time the computer-controlled player has a turn, the game runs slowly because the computer evaluates all potential moves and selects the best one. Which of the following best describes the possibility of improving the running speed of the game?
The game's running speed might be improved by using a process that finds approximate solutions every time the computer-controlled player has a turn.
A researcher wrote a program to simulate the number of mice in an environment that contains predators. The program uses the following procedures. Code for the simulation is shown below. Based on the code, which of the following assumptions is made in the simulation?
The number of predators does not change from day to day.
Consider the following program, which is intended to display the number of times a number target appears in a list. Which of the following best describes the behavior of the program?
The program correctly displays the number of times target appears in the list.
Consider the following program. Which of the following describes the result of executing the program?
The program displays the sum of the even integers from 2 to 20.
Consider the following program. Which of the following describes the result of executing the program?
The program displays the sum of the odd integers from 1 to 19.
Which of the following best explains the ability to solve problems algorithmically?
There exist some problems that cannot be solved algorithmically using any computer.
A team of programmers is designing software. One portion of the project presents a problem for which there is not an obvious solution. After some research, the team determines that the problem is undecidable. Which of the following best explains the consequence of the problem being undecidable?
There is no possible algorithm that can be used to solve all instances of the problem.
Consider the following code segment. What are the contents of yourList after the code segment is executed?
[10, 30, 50, 70]
In a certain video game, players are awarded bonus points at the end of a level based on the value of the integer variable timer. The bonus points are awarded as follows. If timer is less than 30, then 500 bonus points are awarded. If timer is between 30 and 60 inclusive, then 1000 bonus points are awarded. If timer is greater than 60, then 1500 bonus points are awarded. Which of the following code segments assigns the correct number of bonus points to bonus for all possible values of timer ? Select two answers.
bonus = 500 IF times >= 30 bonus = bonus + 500 IF timer > 60 bonus = bonus + 500 IF timer > 60 bonus = 1500 IF timer >= 30 AND timer <= 60 bonus = 1000 IF timer < 30 bonus = 500
The algorithm below is used to simulate the results of flipping a coin 4 times. Consider the goal of determining whether the simulation resulted in an equal number of heads and tails. Step 1: Initialize the variables heads_counter and flip_counter to 0. Step 2: A variable coin_flip is randomly assigned a value of either 0 or 1. If coin_flip has the value 0, the coin flip result is heads, so heads_counter is incremented by 1. Step 3: Increment the value of flip_counter by 1. Step 4: Repeat steps 2 and 3 until flip_counter equals 4. Following execution of the algorithm, which of the following expressions indicates that the simulation resulted in an equal number of heads and tails?
heads_counter = 2
A flowchart provides a way to visually represent an algorithm and uses the following building blocks. In the flowchart below, assume that j and k are assigned integer values. Which of the following initial values of j and k will cause the algorithm represented in the flowchart to result in an infinite loop?
j = 5, k = -5
Consider the following code segment. Which of the following replacements for <MISSING CONDITION> will result in an infinite loop?
j = 6
The variable age is to be used to represent a person's age, in years. Which of the following is the most appropriate data type for age ?
number
The following code segment is used to determine whether a customer is eligible for a discount on a movie ticket. val1 ← (NOT (category = "new")) OR (age ≥ 65) val2 ← (category = "new") AND (age < 12) If category is "new" and age is 20, what are the values of val1 and val2 as a result of executing the code segment?
val1 = false, val2 = false
Which of the following code segments can be used to draw the figure? Select two answers.
x ← 4 y ← 1 r ← 0 REPEAT 3 TIMES { r ← r + 1 y ← y + 1 drawCircle(x, y, r) } x ← 4 y ← 4 r ← 3 REPEAT 3 TIMES { drawCircle(x, y, r) y ← y - 1 r ← r - 1 }