AP CSP BigIdea3 Assignment
AP CSP BigIdea3 Assignment
AP-CSP-BigIdea3-Assignment
1. For which of the following situations would it be best to use a heuristic in order to find a solution that runs in a
reasonable amount of time?
(A) Appending a value to a list of elements, which requires no list elements be examined.
Finding the fastest route that visits every location among locations, which requires possible routes be
(B)
examined.
Performing a binary search for a score in a sorted list of scores, which requires that fewer than scores be
(C)
examined.
Performing a linear search for a name in an unsorted database of people, which requires that up to
(D)
entries be examined.
2. 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 ?
AP-CSP-BigIdea3-Assignment
Step 1:
(A) 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.
(B)
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.
(C) 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.
(D) 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. 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
(A)
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
(B)
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
(C)
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
(D)
maximum, set the maximum equal to num.
AP-CSP-BigIdea3-Assignment
4. 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?
AP-CSP-BigIdea3-Assignment
Step 1:
Keep moving forward, one square at a time, until the square to the right of the robot is black.
(A) 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
Step 2:
Turn right and move one square forward.
Step 1:
Move forward three squares.
(C)
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.
(D) 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.
5. 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?
AP-CSP-BigIdea3-Assignment
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
(A)
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
(B)
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
(C)
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
(D)
gate is open. If it is not, turn on the motor.
6. 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 last number, swap them. Then, if the first number is greater than the
(A)
middle number, swap them.
If the first number is greater than the middle number, swap them. Then, if the middle number is greater than
(B)
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
(C)
the last number, swap them. Then, if the first 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
(D)
the last number, swap them. Then, if the first number is greater than the middle number, swap them.
7. Which of the following algorithms display all integers between 1 and 20, inclusive, that are not divisible by 3 ?
AP-CSP-BigIdea3-Assignment
Step 1:
Set x to 0.
Step 2:
Increment x by 1.
A
Step 3:
If x is not divisible by 3, then display x.
Step 4:
Repeat steps 2 and 3 until x is 20.
Step 1:
Set x to 0.
B
Step 2: If x is divisible by 3, then display x.
Step 3:
Increment x by 1.
Step 1:
Set x to 1.
C
Step 2: If x is divisible by 3, then do nothing; otherwise display x.
Step 3:
Increment x by 1.
Step 1:
Set x to 1.
D
Step 2: If x is divisible by 3, then do nothing; otherwise display x.
Step 3:
Increment x by 1.
8. 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?
AP-CSP-BigIdea3-Assignment
Step 1:
Assign each student a unique integer from 1 to 30.
Step 2:
Generate a random integer n from 1 to 15.
(A) Step 3:
Select the student who is currently assigned integer n and display the student’s name.
Step 4:
Generate a new random integer n from 16 to 30.
Step 5:
Select the student who is currently assigned integer n and display the student’s name.
Step 1:
Assign each student a unique integer from 1 to 30.
Step 2:
Generate a random integer n from 1 to 30.
(B) Step 3:
Select the student who is currently assigned integer n and display the student’s name.
Step 4:
Generate a new random integer n from 1 to 30.
Step 5:
Select the student who is currently assigned integer n and display the student’s name.
Step 1:
Assign each student a unique integer from 1 to 30.
Step 2:
Generate a random odd integer n from 1 to 29.
(C) Step 3:
Select the student who is currently assigned integer n and display the student’s name.
Step 4:
Generate a new random even integer n from 2 to 30.
Step 5:
Select the student who is currently assigned integer n and display the student’s name.
(D) Step 1:
Assign each student a unique integer from 1 to 30.
AP-CSP-BigIdea3-Assignment
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
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.
9. 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 ?
(A) Boolean
(B) number
(C) string
(D) list
10. The variable isOpen is to be used to indicate whether or not a store is currently open. Which of the following is
the most appropriate data type for isOpen ?
(A) Boolean
(B) number
(C) string
(D) list
11. A teacher is writing a code segment that will use variables to represent a student’s name and whether or not the
student is currently absent. Which of the following variables are most appropriate for the code segment?
(A) A string variable named s and a Boolean variable named a
(B) A string variable named s and a numeric variable named n
(C) A string variable named studentName and a Boolean variable named isAbsent
(D) A string variable named studentName and a numeric variable named numAbsences
AP-CSP-BigIdea3-Assignment
12. 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 ?
AP-CSP-BigIdea3-Assignment
AP-CSP-BigIdea3-Assignment
}
ELSE
{
bonus ← score
}
}
13. The cost of a customer’s electricity bill is based on the number of units of electricity the customer uses.
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?
(A)
(B)
(C)
(D)
14. Which of the following is a benefit of using a list as a data abstraction in a program?
AP-CSP-BigIdea3-Assignment
(A) Lists often allow their size to be easily updated to hold as many data values as needed.
(B) Lists convert all elements to strings so that they can be inspected character-by-character.
(C) Lists prevent duplicate data values from appearing in the list.
(D) Lists are used to store all input data so that there is a running record of all user input.
15. 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?
(A) Keeping the numeric values in a list makes it easier to round a number to the nearest integer.
(B) Keeping the numeric values in a list makes it easier to apply the same computation to every data element.
Keeping the numeric values in a list makes it easier to prevent a program from unintentionally changing the
(C)
value of a variable.
Keeping the numeric values in a list makes it easier to prevent a program from attempting to access an index
(D)
beyond the length of the list.
16. Which of the following is a benefit of using a simulation instead of an experiment to make a prediction?
C A simulation always produces the same output, so its results can be verified.
D A simulation produces results that are more accurate than experimental results.
18. A sorted list of numbers contains 200 elements. Which of the following is closest to the maximum number of list
elements that will need to be examined when performing a binary search for a particular value in the list?
(A) 5
(B) 8
(C) 100
(D) 200
AP-CSP-BigIdea3-Assignment
19. A time stamp indicates the date and time that a measurement was taken. A data scientist has a list containing 10,000
time stamps, sorted in chronological order. Which of the following is closest to the maximum number of values that
will need to be examined when performing a binary search for a value in the list?
(A) 10
(B) 15
(C) 5,000
(D) 10,000
20. The list listOne is a sorted list of numbers that contains 700 elements. The list listTwo is a sorted list of
numbers that contains 900 elements. Let x represent the maximum number of list elements that will need to be
examined when performing a binary search for a value in listOne, and let y represent the maximum number of
list elements that will need to be examined when performing a binary search for a value in listTwo. Which of
the following statements about x and y is true?
(A) The value of x is approximately equal to the value of y.
(B) The value of x is approximately 10 less than the value of y.
(C) The value of x is approximately 13 less than the value of y.
(D) The value of x is approximately 200 less than the value of y.
AP-CSP-BigIdea3-Assignment
21. Consider a game where a player spins a wheel divided into four identical sections, labeled A, B, C, and D. If the
player spins A, the score is 10. If the player spins B, the score is 5. If the player spins C or D, the score is -1.
AP-CSP-BigIdea3-Assignment
Which of the following could be used as a replacement for <MISSING STATEMENT> so the code segment
works as intended?
AP-CSP-BigIdea3-Assignment
(A)
(B)
(C)
(D)
22. Assume that both lists and strings are indexed starting with index 1.
Let myWord be the element at index 3 of wordList. Let myChar be the character at index 2 of
myWord. What is the value of myChar ?
(A) "e"
(B) "f\"
(C) "h"
(D) "i"
23. In the following code segment, assume that x and y have been assigned integer values.
sum 0
REPEAT x TIMES
{
REPEAT y TIMES
{
sum ← sum + 1
}
}
At the end of which of the following code segments is the value of sum the same as the value of sum at the end
of the preceding code segment?
AP-CSP-BigIdea3-Assignment
sum 0
z x + y
REPEAT z TIMES
A {
sum ← sum + 1
}
sum 0
z x * y
REPEAT z TIMES
B {
sum ← sum + 1
}
sum 0
REPEAT x TIMES
{
sum ← sum + 1
C }
REPEAT y TIMES
{
sum ← sum + 1
}
sum 0
REPEAT y TIMES
{
REPEAT x TIMES
D {
sum ← sum + 1
}
}
AP-CSP-BigIdea3-Assignment
24. Consider the following code segment, where exam and presentation are integer variables and grade is
a string variable.
Under which of the following conditions will the value "C" be assigned to the variable grade ?
(A) When the value of exam is 70 and the value of presentation is 50
(B) When the value of exam is 70 and the value of presentation is 80
(C) When the value of exam is 80 and the value of presentation is 60
(D) When the value of exam is 80 and the value of presentation is 80
25. 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?
(A) The problem can be solved algorithmically, but it will require an unreasonably long amount of time.
(B) The problem can be solved algorithmically, but it will require an unreasonably large amount of data storage.
(C) There is no possible algorithm that can be used to solve all instances of the problem.
There are several different possible algorithms that can solve the problem, but there is controversy about
(D)
which is the most efficient.
AP-CSP-BigIdea3-Assignment
What are the contents of yourList after the code segment is executed?
(A) [10, 30, 50, 70]
(B) [20, 40, 60, 80]
(C) [10, 30, 50, 70, 20, 40, 60, 80]
(D) [20, 40, 60, 80, 10, 30, 50, 70]
27. A city planner is using simulation software to study crowd flow out of a large arena after an event has ended. The
arena is located in an urban city. Which of the following best describes a limitation of using a simulation for this
purpose?
(A) The model used by the simulation software cannot be modified once the simulation has been used.
(B) The model used by the simulation software often omits details so that it is easier to implement.
Running a simulation requires more time to generate data from trials than observing the crowd exiting the
(C)
arena at various events.
Running a simulation requires a large number of observations to be collected before it can be used to explore
(D)
a problem.
28. A student wants to determine whether a certain problem is undecidable. Which of the following will demonstrate
that the problem is undecidable?
Show that for one instance of the problem, an algorithm can be written that is always capable of providing a
(A)
correct yes-or-no answer.
Show that for one instance of the problem, no algorithm can be written that is capable of providing a correct
(B)
yes-or-no answer.
Show that for one instance of the problem, a heuristic is needed to write an algorithm that is capable of
(C)
providing a correct yes-or-no answer.
Show that for one instance of the problem, an algorithm that runs in unreasonable time can be written that is
(D)
capable of providing a correct yes-or-no answer.
29. The following code segment is used to determine whether a customer is eligible for a discount on a movie ticket.
If category is "new" and age is 20, what are the values of val1 and val2 as a result of executing
the code segment?
AP-CSP-BigIdea3-Assignment
AP-CSP-BigIdea3-Assignment
Which of the following CANNOT be displayed as a result of executing the code segment?
(A) 1 1 1 1
(B) 1 2 3 2
(C) 1 2 3 4
(D) 1 3 2 4
AP-CSP-BigIdea3-Assignment
The drawCircle procedure is to be used to draw the following figure on a coordinate grid.
Let the value of the variable x be 2, the value of the variable y be 2, and the value of the variable r be
1. Which of the following code segments can be used to draw the figure?
drawCircle(x, y, r)
drawCircle(x, y + 2, r)
(A) drawCircle(x + 2, y, r)
drawCircle(x + 2, y + 2, r)
drawCircle(x, y, r)
drawCircle(x, y + 3, r)
(B) drawCircle(x + 3, y, r)
drawCircle(x + 3, y + 3, r)
drawCircle(x, y, r + 2)
drawCircle(x, y + 2, r + 2)
(C) drawCircle(x + 2, y, r + 2)
drawCircle(x + 2, y + 2, r + 2)
drawCircle(x, y, r + 3)
drawCircle(x, y + 3, r + 3)
(D) drawCircle(x + 3, y, r + 3)
drawCircle(x + 3, y + 3, r + 3)
AP-CSP-BigIdea3-Assignment
The drawLine procedure is to be used to draw the following figure on a coordinate grid.
Let the value of the variable xVal be 6 and the value of the variable yVal be 5. Which of the following
code segments can be used to draw the figure?
drawLine(1, 5, xVal, yVal)
(A) drawline(1, 5, xVal, yVal + 2)
drawline(1, 5, xVal, yVal + 2)
drawLine(1, 5, xVal, yVal)
(B) drawline(1, 5, xVal, yVal + 2)
drawline(1, 5, xVal, yVal - 2)
drawLine(1, 5, xVal, yVal)
(C) drawline(1, 5, xVal + 2, yVal + 2)
drawline(1, 5, xVal + 2, yVal - 2)
drawLine(1, 5, xVal, yVal)
(D) drawline(1, 5, xVal + 2, yVal + 2)
drawline(1, 5, xVal - 2, yVal - 2)
AP-CSP-BigIdea3-Assignment
34. 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.
Number of Number of
4 17
5 24
6 35
7 50
Based on the values in the table, which of the following best characterizes the algorithm for drawing shapes,
where is a very large number?
The algorithm runs in a reasonable amount of time because it will use approximately steps to draw
(A)
shapes.
The algorithm runs in a reasonable amount of time because it will use approximately steps to draw
(B)
shapes.
The algorithm runs in an unreasonable amount of time because it will use approximately steps to draw
(C)
shapes.
The algorithm runs in an unreasonable amount of time because it will use approximately steps to draw
(D)
shapes.
35. To attend a particular camp, a student must be either at least 13 years old or in grade 9 or higher, but must not yet be
18 years old. Let age represent a student’s age and let grade represent the student’s grade level. Which of the
following expressions evaluates to true if the student is eligible to attend the camp and evaluates to false
otherwise?
(A) ((age ≥ 13) OR (grade ≥ 9)) AND (age ≤ 18)
(B) ((age ≥ 13) OR (grade ≥ 9)) AND (age < 18)
(C) ((age ≥ 13) OR (grade ≥ 9)) OR (age ≤ 18)
(D) ((age ≥ 13) OR (grade ≥ 9)) OR (age < 18)
36. Let n be an integer value. Which of the following expressions evaluates to true if and only if n is a two-digit
integer (i.e., in the range from 10 to 99, inclusive)?
(A) n = (n MOD 100)
(B) (n ≥ 10) AND (n < 100)
(C) (n < 10) AND (n ≥ 100)
(D) (n > 10) AND (n < 99)
AP-CSP-BigIdea3-Assignment
37. A student has a data file containing 10,000 numerical values. The student is writing a program to compute the
average of the numbers contained in the file. Which of the following procedures is most likely to be useful in the
student’s program?
(A) A procedure that returns the quotient when dividing one value by another
(B) A procedure that returns the sum when adding one value to another
(C) A procedure that returns the sum of the values in the file
(D) A procedure that returns true if the file contains any duplicate values and returns false otherwise
38. A student is writing a program that is intended to replace each negative value in a particular column of a
spreadsheet with the value 0. Which of the following procedures is most likely to be useful in the student’s
program?
A procedure containsNegatives, which returns true if any negative values appear in the column
(A)
and returns false otherwise.
(B) A procedure countNegatives, which returns the number of negative values that appear in the column.
A procedure findNegative, which returns the row number of the first negative value that appears in the
(C)
column or -1 if there are no negative values.
(D) A procedure minimum, which returns the minimum value that appears in the column.
39. Which of the following procedures would be most useful as part of a program to determine whether a word appears
in two different text files?
A procedure getWords, which takes a positive integer n and a text file as input and returns the first n
(A)
words in the text file.
A procedure isFound, which takes a word and a text file as input and returns true if the word appears
(B)
in the text file
A procedure textMatch, which takes two text files as input and returns true if the two text files are
(C)
identical.
A procedure sameSize, which takes two text files as input and returns true if the two text files
(D)
contain the same number of words.
Which of the following code segments can be used to store "noon" in the string variable word ?
AP-CSP-BigIdea3-Assignment
word "no"
(A) word concat(reverse(word), word)
word "no"
(B) word concat(reverse(word), reverse(word))
word "on"
(C) word concat(reverse(word), word)
word "on"
(D) word concat(reverse(word), reverse(word))
Assume that the string oldString contains at least 4 characters. A programmer is writing a code segment that is
intended to remove the first two characters and the last two characters from oldString and assign the result to
newString.
For example, if oldString contains "student", then newString should contain "ude".
Which of the following code segments can be used to assign the intended string to newString ?
AP-CSP-BigIdea3-Assignment
PROCEDURE proc1(str)
{
DISPLAY(str)
DISPLAY("happy")
}
PROCEDURE proc2(str1, str2)
{
proc1(str2)
DISPLAY(str1)
}
43. In which of the following scenarios would a simulation be the LEAST beneficial?
(A) An engineering company wants to test whether a change to a car design will negatively affect fuel efficiency.
(B) An insurance company wants to study the effect of cold weather patterns on health-care costs.
(C) A manufacturing company wants to determine whether using robots in its facility will increase productivity.
A retail company wants to determine the most popular item that was sold on the company’s Web site last
(D)
month.
44. For which of the following problems is using a simulation LEAST likely to be beneficial?
(A) Determining the longest word in a textbook
(B) Minimizing the customer wait times at a bank
(C) Predicting the outcomes of weather patterns
(D) Studying the formation of a galaxy
45. In which of the following scenarios is using a simulation more beneficial than performing a calculation?
AP-CSP-BigIdea3-Assignment
46. In the following statement, val1, val2, and result are Boolean variables.
Which of the following code segments produce the same result as the statement above for all possible values of
val1 and val2 ?
AP-CSP-BigIdea3-Assignment
AP-CSP-BigIdea3-Assignment
48. In the following expression, the variable truckWeight has the value 70000 and the variable
weightLimit has the value 80000.
AP-CSP-BigIdea3-Assignment
result 1
IF(score1 > 500)
{
result ← result + 1
IF(score2 > 500)
{
result ← result + 1
}
ELSE
{
result ← result + 2
}
}
ELSE
{
result ← result + 5
IF(score2 > 500)
{
result ← result + 1
}
ELSE
{
result ← result - 1
}
}
If the value of score1 is 350 and the value of score2 is 210, what will be the value of result after
the code segment is executed?
(A) 3
(B) 4
(C) 5
(D) 7
AP-CSP-BigIdea3-Assignment
AP-CSP-BigIdea3-Assignment
Which of the following initial values of the variable y would result in the variable z being set to 2 after the
code segment is executed?
(A) 1
(B) 2
(C) 3
(D) 4
AP-CSP-BigIdea3-Assignment
What are the values of count1 and count2 as a result of executing the code segment?
(A) count1 = 2, count2 = 2
(B) count1 = 2, count2 = 3
(C) count1 = 3, count2 = 2
(D) count1 = 5, count2 = 0
AP-CSP-BigIdea3-Assignment
What are the values of first and second as a result of executing the code segment?
(A) The value of first is true, and the value of second is true.
(B) The value of first is true, and the value of second is false.
(C) The value of first is false, and the value of second is true.
(D) The value of first is false, and the value of second is false.
AP-CSP-BigIdea3-Assignment
58. A computer scientist is analyzing four different algorithms used to sort a list. The table below shows the number of
steps each algorithm took to sort lists of different sizes.
List Size
1 10 2 1 1
2 20 4 2 4
3 30 8 6 9
4 40 16 24 16
5 50 32 120 25
Based on the values in the table, which of the algorithms appear to run in reasonable time?
A Algorithm A
B Algorithm B
C Algorithm C
D Algorithm D
x 25
y 50
z 75
x y
y z
z x
Which of the variables have the value 50 after executing the code segment?
(A) x only
(B) y only
(C) x and z only
(D) x, y, and z
AP-CSP-BigIdea3-Assignment
60. Suppose that a list of numbers contains values [-4, -1, 1, 5, 2, 10, 10, 15, 30]. Which of the
following best explains why a binary search should NOT be used to search for an item in this list?
(A) The list contains both positive and negative elements.
(B) The elements of the list are not sorted.
(C) The list contains an odd number of elements.
(D) The list contains duplicate elements.
61. In a certain video game, the variable maxPS represents the maximum possible score a player can earn. The
maximum possible score depends on the time it takes the player to complete the game. The value of maxPS
should be 30 if time is greater than 120 and 50 otherwise.
Which of the following code segments correctly sets the value of maxPS based on the value of time ?
AP-CSP-BigIdea3-Assignment
62. In a certain game, a player may have the opportunity to attempt a bonus round to earn extra points. In a typical
game, a player is given 1 to 4 bonus round attempts. For each attempt, the player typically earns the extra points
70% of the time and does not earn the extra points 30% of the time.
The following code segment can be used to simulate the bonus round.
63. The transportation department plans to build a new high-speed train route between two cities. The transportation
department wants to implement a simulation of the train before any construction begins on this project. Which of
the following statements is true about the use of a simulation for this project?
(A) A simulation cannot be used to test the train under varying weather conditions.
(B) Implementing a simulation is likely to increase the overall costs associated with the project.
(C) Other high-speed train routes have been constructed in other locations, so a simulation is not needed.
(D) Using a simulation may expose potential safety issues that can be corrected before construction begins.
AP-CSP-BigIdea3-Assignment
64. Consider the following spinner, which is used to determine how pieces are to be moved on a game board. Each
region is of equal size.
Which of the following code segments can be used to simulate the behavior of the spinner?
AP-CSP-BigIdea3-Assignment
(A)
(B)
(C)
(D)
AP-CSP-BigIdea3-Assignment
65. Consider the following code segment, which is intended to store ten consecutive even integers, beginning with
2, in the list evenList. Assume that evenList is initially empty.
i 1
REPEAT 10 TIMES
{
<MISSING CODE>
}
Which of the following can be used to replace <MISSING CODE> so that the code segment works as intended?
APPEND(evenList, i)
(A) i i + 2
i i + 2
(B) APPEND(evenList, i)
APPEND(evenList, 2 * i)
(C) i i + 1
i i + 1
(D) APPEND(evenList, 2 * i)
66. Which of the following code segments can be used to interchange the values of the variables num1 and num2 ?
(A)
(B)
(C)
(D)
AP-CSP-BigIdea3-Assignment
67. The figure below shows a circuit composed of two logic gates. The output of the circuit is true.
68. A spinner contains 12 regions of equal size. The regions are numbered 1 to 12. Which of the following code
segments can be used to simulate the results of spinning the spinner three times and assigns the sum of the values
obtained by the three spins to the variable sum ?
(A) sum RANDOM(1, 12) + RANDOM(1, 12) + RANDOM(1, 12)
(B) sum RANDOM(1, 36)
(C) sum 3 * RANDOM(1, 12)
(D) sum 12 * RANDOM(1, 3)
69. A teacher stores the most recent quiz scores for her class in the list scores. The first element in the list holds the
maximum possible number of points that can be awarded on the quiz, and each remaining element holds one
student’s quiz score. Assume that scores contains at least two elements. Which of the following code segments
will set the variable found to true if at least one student scored the maximum possible number of points on
the quiz and will set found to false otherwise?
AP-CSP-BigIdea3-Assignment
(A)
(B)
(C)
AP-CSP-BigIdea3-Assignment
(D)
70. Three words are stored in the variables word1, word2, and word3. The values of the variables are to be
updated as shown in the following table.
Which of the following code segments can be used to update the values of the variables as shown in the table?
temp word1
(A) word3 word1
word1 temp
temp word1
(B) word1 word3
word3 temp
temp word1
word1 word2
(C) word2 word3
word3 temp
temp word3
word3 word2
(D) word2 word1
word1 temp
AP-CSP-BigIdea3-Assignment
The drawCircle procedure is to be used to draw the following figure on a coordinate grid.
Which of the following code segments can be used to draw the figure?
AP-CSP-BigIdea3-Assignment
x 4
y 1
r 0
REPEAT 3 TIMES
A {
drawCircle(x, y, r)
r ← r + 1
y ← y + 1
}
x 4
y 1
r 0
REPEAT 3 TIMES
B {
r ← r + 1
y ← y + 1
drawCircle(x, y, r)
}
x 4
y 4
r 3
REPEAT 3 TIMES
C {
drawCircle(x, y, r)
y ← y - 1
r ← r - 1
}
x 4
y 4
r 3
REPEAT 3 TIMES
D {
y ← y - 1
r ← r - 1
drawCircle(x, y, r)
}
AP-CSP-BigIdea3-Assignment
The variable initials is to be assigned a string consisting of the first letter of the string firstName
followed by the first letter of the string lastName. Which of the following assigns the correct string to
initials ?
(A) initials concat(prefix(firstName, 1), prefix(lastName, 1))
(B) initials concat(prefix(firstName, 2), prefix(lastName, 2))
(C) initials prefix(concat(firstName, lastName), 1)
(D) initials prefix(concat(firstName, lastName), 2)
73. A student is developing a program that allows users to look up the definitions of words that appear in a book.
The student plans to perform a large number of searches through a dictionary containing words and their definitions.
The student will use a procedure written by a computer scientist to quickly search the dictionary (and knows that the
procedure will return a definition if one is available). The student cannot modify the search procedure written by the
computer scientist but can call the procedure by supplying a word.
Which of the following is a true statement about the student’s use of the computer scientist’s search procedure?
(A) The student is changing the search procedure’s internal abstractions.
The student is modifying the search procedure to take a definition as an argument and return the
(B)
corresponding word.
The student is reusing the computer scientist’s procedural abstraction by knowing what the procedure does
(C)
without knowing how it does it.
The student is reusing the computer scientist’s procedural abstraction by using duplicate code each time a
(D)
search needs to occur.
AP-CSP-BigIdea3-Assignment
74. Consider the following procedures, which are used to control a device that draws lines on paper.
Consider the goal of using the device to produce the following drawing, where each line shown has a length of 10
units and the horizontal lines are 10 units apart.
The device is positioned at the upper-left corner of a sheet of paper and is facing right. Which of the following code
segments will produce the drawing shown?
AP-CSP-BigIdea3-Assignment
penDown()
goForward(10)
turnRight(90)
(A) goForward(10)
turnRight(90)
goForward(10)
penDown()
goForward(10)
penUp()
(B) turnRight(90)
turnRight(90)
penDown()
goForward(10)
penDown()
goForward(10)
turnRight(90)
(C) penUp()
goForward(10)
turnRight(90)
penDown()
penDown()
goForward(10)
penUp()
turnRight(90)
(D) goForward(10)
turnRight(90)
penDown()
goForward(10)
75. A large number of genetic codes are stored as binary values in a list. Which one of the following conditions must be
true in order for a researcher to obtain the correct result when using a binary search algorithm to determine if a
given genetic code is in the list?
(A) The genetic codes must be converted from binary to decimal numbers.
(B) The list must be sorted based on the genetic code values.
(C) The number of genetic code values in the list must be a power of 2.
(D) The number of genetic code values in the list must be even.
AP-CSP-BigIdea3-Assignment
76. The code segment below uses the procedure IsFound (list, item), which returns true if item appears in list and
returns false otherwise. The list resultList is initially empty.
Which of the following best describes the contents of resultList after the code segment is executed?
(A) All elements in inputList1 followed by all elements in inputList2
(B) Only elements that appear in both inputList1 and inputList2
(C) Only elements that appear in either inputList1 or inputList2 but not in both lists
(D) Only elements that appear in inputList1 but not in inputList2
77. The list wordList contains a list of 10 string values. Which of the following is a valid index for the list?
(A) -1
(B) "hello"
(C) 2.5
(D) 4
DISPLAY(doSomething(10, 20))
AP-CSP-BigIdea3-Assignment
If the value of x is 3 and the value of y is 5, what is displayed as a result of executing the code segment?
(A) -2
(B) 2
(C) 8
(D) Nothing will be displayed.
80. To qualify for a particular scholarship, a student must have an overall grade point average of 3.0 or above and must
have a science grade point average of over 3.2. Let overallGPA represent a student’s overall grade point
average and let scienceGPA represent the student’s science grade point average. Which of the following
expressions evaluates to true if the student is eligible for the scholarship and evaluates to false otherwise?
(A) (overallGPA > 3.0) AND (scienceGPA > 3.2)
(B) (overallGPA > 3.0) AND (scienceGPA ≥ 3.2)
(C) (overallGPA ≥ 3.0) AND (scienceGPA > 3.2)
(D) (overallGPA ≥ 3.0) AND (scienceGPA ≥ 3.2)
81. For which of the following lists can a binary search be used to search for an item in the list?
82. Which of the following best explains how algorithms that run on a computer can be used to solve problems?
(A) All problems can be solved with an algorithm that runs in a reasonable amount of time.
All problems can be solved with an algorithm, but some algorithms might need a heuristic to run in a
(B)
reasonable amount of time.
All problems can be solved with an algorithm, but some algorithms might run in an unreasonable amount of
(C)
time.
(D) Some problems cannot be solved by an algorithm.
AP-CSP-BigIdea3-Assignment
83. Consider the following code segment with an integer variable num.
IF(num > 0)
{
DISPLAY("positive")
}
IF(num < 0)
{
DISPLAY("negative")
}
IF(num = 0)
{
DISPLAY("zero")
}
Which of the following code segments is equivalent to the code segment above?
AP-CSP-BigIdea3-Assignment
IF(num < 0)
{
DISPLAY("negative")
}
ELSE
{
(A) DISPLAY("positive")
}
IF(num = 0)
{
DISPLAY("zero")
}
IF(num < 0)
{
DISPLAY("negative")
}
ELSE
{
IF(num = 0)
(B) {
DISPLAY("zero")
}
ELSE
{
DISPLAY("positive")
}
}
IF(num ≤ 0)
{
DISPLAY("negative")
}
ELSE
{
IF(num = 0)
(C) {
DISPLAY("zero")
}
ELSE
{
DISPLAY("positive")
}
}
IF(num ≤ 0)
{
DISPLAY("negative")
}
IF(num = 0)
{
(D) DISPLAY("zero")
}
ELSE
{
DISPLAY("positive")
}
AP-CSP-BigIdea3-Assignment
84. A computer program contains code in several places that asks a user to enter an integer within a specified range of
values. The code repeats the input request if the value that the user enters is not within the specified range. A
programmer would like to create a procedure that will generalize this functionality and can be used throughout the
program. The correct use of the procedure is shown below, where min is the least acceptable value, max is the
greatest acceptable value, and promptString is the string that should be printed to prompt the user enter a
value.
AP-CSP-BigIdea3-Assignment
85. A game program contains the following code to update three score variables, health, food, and
knowledge. The maximum values for the three variables are 100, 80, and 25, respectively.
health health + 10
IF(health > 100)
{
health ← 100
}
food food + 1
IF(food > 80)
{
food ← 80
}
knowledge knowledge + 5
IF(knowledge > 25)
{
knowledge ← 25
}
The game program’s author would like to write a procedure that could be used to update any variable in the
game (myScore) that has a maximum value (myLimit) by a given amount (myAmount). A correct call of
the procedure is shown below.
AP-CSP-BigIdea3-Assignment
AP-CSP-BigIdea3-Assignment
86. A student wrote the following procedure to calculate the sum of the integers from 1 to 5.
The student later decides to modify the procedure to calculate the sum of the integers from 1 to max, which
represents any positive integer greater than 1.
Which of the following changes should be made to the procedure to meet the student’s goal?
AP-CSP-BigIdea3-Assignment
87. Shoppers at a mall were asked whether they preferred wearing gloves or mittens in cold weather. Shoppers’
preferences were stored in the list voteList as strings, with the string "Gloves" representing a preference
for gloves and the string "Mittens" representing a preference for mittens.
The following code segment is intended to traverse the list and display the number of shoppers who chose gloves
and the number of shoppers who chose mittens.
numGlovesVotes 0
numMittensVotes 0
<MISSING CODE>
{
IF(vote = "Gloves")
{
numGlovesVotes ← numGlovesVotes + 1
}
ELSE
{
numMittensVotes ← numMittensVotes + 1
}
}
DISPLAY(numGlovesVotes)
DISPLAY(" shoppers chose gloves and")
DISPLAY(numMittensVotes)
DISPLAY(" shoppers chose mittens.")
Which of the following should replace <MISSING CODE> so that the code segment works as intended?
(A) IF(vote ≤ LENGTH(voteList))
(B) FOR EACH vote IN voteList
(C) REPEAT LENGTH(voteList) TIMES
(D) REPEAT UNTIL(vote > LENGTH(voteList))
88. Consider the following code segment. Assume that index1 is a number between 1 and
LENGTH(theList), inclusive, and index2 is a number between 2 and LENGTH(theList) -
1, inclusive.
What is the largest possible value that the variable x can have after the code segment executes?
(A) 17
(B) 14
(C) 11
(D) 4
AP-CSP-BigIdea3-Assignment
89. The following grid contains a robot represented as a triangle, which is initially facing right.
The following code segment is intended to move the robot to the gray square.
<MISSING STATEMENT>
{
REPEAT 4 TIMES
{
MOVE_FORWARD()
ROTATE_RIGHT()
}
ROTATE_LEFT()
MOVE_FORWARD()
ROTATE_RIGHT()
}
Which of the following can be used as a replacement for <MISSING STATEMENT> so that the code segment
works as intended?
(A) REPEAT 1 TIMES
(B) REPEAT 2 TIMES
(C) REPEAT 3 TIMES
(D) REPEAT 4 TIMES
AP-CSP-BigIdea3-Assignment
90. 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?
(A) Interchange the ROTATE_RIGHT and the ROTATE_LEFT blocks.
(B) Replace ROTATE_RIGHT with ROTATE_LEFT.
(C) Replace ROTATE_LEFT with ROTATE_RIGHT.
(D) No change is needed; the algorithm is correct as is.
AP-CSP-BigIdea3-Assignment
91. The following question uses a robot in a grid of squares. The robot is represented as a triangle, which is initially
facing toward the top of the grid.
The following code segment moves the robot around the grid. Assume that n is a positive integer.
Line 1: count 0
Line 2: REPEAT n TIMES
Line 3: {
Line 4: REPEAT 2 TIMES
Line 5: {
Line 6: MOVE_FORWARD()
Line 7: }
Line 8: ROTATE_RIGHT()
Line 9: }
Consider the goal of modifying the code segment to count the number of squares the robot visits before execution
terminates. Which of the following modifications can be made to the code segment to correctly count the number of
squares the robot moves to?
(A) Inserting the statement count count + 1 between line 6 and line 7
(B) Inserting the statement count count + 2 between line 6 and line 7
(C) Inserting the statement count count + 1 between line 8 and line 9
(D) Inserting the statement count count + n between line 8 and line 9
AP-CSP-BigIdea3-Assignment
92. The following grid contains a robot represented as a triangle, which is initially facing toward the top of the grid. The
robot can move into a white or gray square but cannot move into a black region.
Which of the following code segments can be used to move the robot to the gray square?
AP-CSP-BigIdea3-Assignment
REPEAT 3 TIMES
{
MOVE_FORWARD()
}
REPEAT 2 TIMES
{
(A) MOVE_FORWARD()
}
REPEAT 3 TIMES
{
MOVE_FORWARD()
}
REPEAT 8 TIMES
{
(B) MOVE_FORWARD()
}
REPEAT 3 TIMES
{
MOVE_FORWARD()
}
ROTATE_LEFT()
REPEAT 2 TIMES
{
(C) MOVE_FORWARD()
}
ROTATE_LEFT()
REPEAT 3 TIMES
{
MOVE_FORWARD()
}
REPEAT 3 TIMES
{
MOVE_FORWARD()
}
ROTATE_LEFT()
REPEAT 2 TIMES
{
(D) MOVE_FORWARD()
}
ROTATE_RIGHT()
REPEAT 3 TIMES
{
MOVE_FORWARD()
}
AP-CSP-BigIdea3-Assignment
What are the contents of secondList after the code segment is executed?
(A) []
(B) ["guitar", "drums", "bass"]
(C) ["flute", "violin"]
(D) ["flute", "violin", "guitar", "drums", "bass"]
94. Three teams (Team A, Team B, and Team C) are participating in a trivia contest. Let scoreA represent the
number of correct questions for Team A, scoreB represent the number of correct questions for Team B, and
scoreC represent the number of correct questions for Team C. Assuming no two teams get the same number of
correct questions, which of the following code segments correctly displays the team with the highest number of
correct questions?
AP-CSP-BigIdea3-Assignment
(A)
(B)
(C)
AP-CSP-BigIdea3-Assignment
(D)
AP-CSP-BigIdea3-Assignment
95. 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 ?
I.
II.
III.
(A) II only
(B) I and II only
(C) I and III only
(D) II and III only
96. A computer science student completes a program and asks a classmate for feedback. The classmate suggests
rewriting some of the code to include more procedural abstraction. Which of the following is NOT a benefit of
procedural abstraction?
AP-CSP-BigIdea3-Assignment
97. 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?
(A) ONE
(B) TWO
(C) THREE
(D) FOUR
AP-CSP-BigIdea3-Assignment
98. In the following procedure, the parameter str is a string and the parameter num is a number.
printArgs("**", 1)
printArgs("*", 2)
Which of the following describes the possible values of ans as a result of executing the code segment?
(A) Any integer value from 1 to 8, inclusive
(B) Any integer value from 1 to 16, inclusive
(C) Any integer value from 4 to 8, inclusive
(D) Any integer value from 7 to 16, inclusive