0% found this document useful (0 votes)
91 views69 pages

AP CSP BigIdea3 Assignment

The document is an AP Computer Science Principles test booklet containing various assignments and questions related to algorithms, data types, and problem-solving techniques. It includes multiple-choice questions that assess understanding of programming concepts, algorithm design, and data abstraction. The questions cover topics such as heuristics, distance calculation, score tracking, and random selection among others.

Uploaded by

seed2014
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
91 views69 pages

AP CSP BigIdea3 Assignment

The document is an AP Computer Science Principles test booklet containing various assignments and questions related to algorithms, data types, and problem-solving techniques. It includes multiple-choice questions that assess understanding of programming concepts, algorithm design, and data abstraction. The questions cover topics such as heuristics, distance calculation, score tracking, and random selection among others.

Uploaded by

seed2014
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 69

AP COMPUTER SCIENCE PRINCIPLES Test Booklet

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.

Value of num1 Value of num2 Distance Between num1 and num2


5 2 3
1 8 7
-3 4 7

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

AP Computer Science Principles Page 1 of 69


Test Booklet

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.

Page 2 of 69 AP Computer Science Principles


Test Booklet

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 Computer Science Principles Page 3 of 69


Test Booklet

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

(B) 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.
(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?

Page 4 of 69 AP Computer Science Principles


Test Booklet

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 ?

Select two answers.

AP Computer Science Principles Page 5 of 69


Test Booklet

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 4: Repeat steps 2 and 3 until x is greater than 20.

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 4: Repeat steps 2 and 3 until x is 20.

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.

Step 4: Repeat steps 2 and 3 until x is greater than 20.

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?

Page 6 of 69 AP Computer Science Principles


Test Booklet

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 Computer Science Principles Page 7 of 69


Test Booklet

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

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.

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

Page 8 of 69 AP Computer Science Principles


Test Booklet

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 ?

Select two answers.

AP Computer Science Principles Page 9 of 69


Test Booklet

AP-CSP-BigIdea3-Assignment

IF(score > 100)


{
bonus ← score * 10
}
ELSE
{
IF(score ≥ 50)
A {
bonus ← score
}
ELSE
{
bonus ← 0
}
}
IF(score ≥ 50)
{
IF(score > 100)
{
bonus ← score * 10
}
ELSE
B {
bonus ← 0
}
}
ELSE
{
bonus ← score
}
IF(score < 50)
{
bonus ← 0
}
ELSE
{
IF(score ≥ 50)
C {
bonus ← score
}
ELSE
{
bonus ← score * 10
}
}
IF(score < 50)
{
bonus ← 0
}
D ELSE
{
IF(score > 100)
{
bonus ← score * 10

Page 10 of 69 AP Computer Science Principles


Test Booklet

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.

• 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?

(A)

(B)

(C)

(D)

14. Which of the following is a benefit of using a list as a data abstraction in a program?

AP Computer Science Principles Page 11 of 69


Test Booklet

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?

Select two answers.


A simulation allows investigation of a phenomenon without the real-world limitations on time, safety, or
A
budget.
B A simulation can be used to model real-world events that are impractical for experiments.

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.

17. Which of the following are benefits of procedural abstraction?

Select two answers.


Procedural abstraction prevents programmers from accidentally using the intellectual property of other
A
programmers.
B Procedural abstraction eliminates the need for programmers to document their code.

C 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
D
of the code block.

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

Page 12 of 69 AP Computer Science Principles


Test Booklet

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 Computer Science Principles Page 13 of 69


Test Booklet

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.

The following code segment is intended to implement the game.

Page 14 of 69 AP Computer Science Principles


Test Booklet

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 Computer Science Principles Page 15 of 69


Test Booklet

AP-CSP-BigIdea3-Assignment

(A)

(B)

(C)

(D)

22. Assume that both lists and strings are indexed starting with index 1.

The list wordList has the following contents.

["abc", "def\", "ghi", "jkl"]

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?

Select two answers.

Page 16 of 69 AP Computer Science Principles


Test Booklet

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 Computer Science Principles Page 17 of 69


Test Booklet

AP-CSP-BigIdea3-Assignment

24. Consider the following code segment, where exam and presentation are integer variables and grade is
a string variable.

IF((exam > 90) AND (presentation > 80))


{
grade ← "A"
}
IF((exam > 80) OR (presentation > 75))
{
grade ← "B"
}
ELSE
{
IF((exam > 70) OR (presentation > 60))
{
grade ← "C"
}
ELSE
{
IF(exam > 60)
{
grade ← "D"
}
ELSE
{
grade ← "F"
}
}
}

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.

Page 18 of 69 AP Computer Science Principles


Test Booklet

AP-CSP-BigIdea3-Assignment

26. Consider the following code segment.

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.

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?

AP Computer Science Principles Page 19 of 69


Test Booklet

AP-CSP-BigIdea3-Assignment

(A) val1 = true, val2 = true


(B) val1 = true, val2 = false
(C) val1 = false, val2 = true
(D) val1 = false, val2 = false

30. Consider the following code segment.

What is displayed as a result of executing the code segment?


(A) 1 3 5
(B) 5 3 1
(C) 100 300 500
(D) 500 300 100

Page 20 of 69 AP Computer Science Principles


Test Booklet

AP-CSP-BigIdea3-Assignment

31. Consider the following code segment.

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 Computer Science Principles Page 21 of 69


Test Booklet

AP-CSP-BigIdea3-Assignment

32. Consider the following procedure.

Procedure Call Explanation


drawCircle(xPos, Draws a circle on a coordinate grid with center (xPos, yPos)
yPos, rad) and radius rad

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)

Page 22 of 69 AP Computer Science Principles


Test Booklet

AP-CSP-BigIdea3-Assignment

33. Consider the following procedure.

Procedure Call Explanation


drawLine(x1, y1, Draws a line segment on a coordinate grid with endpoints at coordinates
x2, y2) (x1, y1) and (x2, y2)

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 Computer Science Principles Page 23 of 69


Test Booklet

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

Shapes Drawn Steps

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)

Page 24 of 69 AP Computer Science Principles


Test Booklet

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.

40. Consider the following procedures for string manipulation.

Procedure Call Explanation


concat(str1, Returns a single string consisting of str1 followed by str2. For example,
str2) concat("key", "board") returns "keyboard".
Returns the reverse of the string str. For example, reverse("abcd") returns
reverse(str)
"dcba".

Which of the following code segments can be used to store "noon" in the string variable word ?

AP Computer Science Principles Page 25 of 69


Test Booklet

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))

41. Consider the following procedures for string manipulation.

Procedure Call Explanation


concat(str1, Returns a single string consisting of str1 followed by str2. For example,
str2) concat("key", "board") returns "keyboard".
Returns a substring of consecutive characters from str, starting with the
substring(str, character at position start and containing length characters. The first
start, length) character of str is located at position 1. For example,
substring("delivery", 3, 4) returns "live".
Returns the number of characters in str. For example, len("pizza")
len(str)
returns 5.

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 ?

Select two answers.

A newString substring(oldString, 3, len(oldString) - 4)

B newString substring(oldString, 3, len(oldString) - 2)


tempString substring(oldString, 3, len(oldString) - 2)
C newString substring(tempString, 1, len(tempString) - 2)
tempString1 substring(oldString, 1, 2)
D tempString2 substring(oldString, len(oldString) - 2, 2)
newString concat(tempString1, tempString2)

Page 26 of 69 AP Computer Science Principles


Test Booklet

AP-CSP-BigIdea3-Assignment

42. Consider the following procedures.

PROCEDURE proc1(str)
{
DISPLAY(str)
DISPLAY("happy")
}
PROCEDURE proc2(str1, str2)
{
proc1(str2)
DISPLAY(str1)
}

What is displayed as a result of the procedure call proc2("birthday", "to you") ?


(A) birthday happy to you
(B) birthday happy birthday
(C) to you birthday happy
(D) to you happy birthday

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?

Select two answers.

A Determining the average grade of the students in a certain class

B Keeping track of the high score in a game

C Investigating ways to reduce the amount of trash in the ocean

D Studying the effect of a genetic change in a population

AP Computer Science Principles Page 27 of 69


Test Booklet

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 ?

Select two answers.

Page 28 of 69 AP Computer Science Principles


Test Booklet

AP-CSP-BigIdea3-Assignment

AP Computer Science Principles Page 29 of 69


Test Booklet

AP-CSP-BigIdea3-Assignment

47. Consider the following code segment.

What is the value of r as a result of executing the code segment?


(A) 10
(B) 20
(C) 30
(D) 40

48. In the following expression, the variable truckWeight has the value 70000 and the variable
weightLimit has the value 80000.

truckWeight < weightLimit

What value does the expression evaluate to?


(A) 70000
(B) 80000
(C) true
(D) false

Page 30 of 69 AP Computer Science Principles


Test Booklet

AP-CSP-BigIdea3-Assignment

49. Consider the following code segment.

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 Computer Science Principles Page 31 of 69


Test Booklet

AP-CSP-BigIdea3-Assignment

50. Consider the following code segment.

What is the value of sum after the code segment is executed?


(A) 12
(B) 14
(C) 16
(D) 18

51. Consider the following code segment.

What is the value of result after the code segment is executed?


(A) 6
(B) 10
(C) 15
(D) 21

Page 32 of 69 AP Computer Science Principles


Test Booklet

AP-CSP-BigIdea3-Assignment

52. Consider the following code segment.

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

53. Consider the following code segment.

What is displayed as a result of executing the code segment?


(A) true false false
(B) true false true
(C) true true false
(D) true true true

AP Computer Science Principles Page 33 of 69


Test Booklet

AP-CSP-BigIdea3-Assignment

54. Consider the following code segment.

What is displayed as a result of executing the code segment?


(A) true true true
(B) false false false
(C) true false true
(D) false false true

55. Consider the following code segment.

theList [-2, -1, 0, 1, 2]


count1 0
count2 0
FOR EACH value IN theList
{
IF(value > 0)
{
count1 ← count1 + 1
}
ELSE
{
count2 ← count2 + 1
}
}

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

Page 34 of 69 AP Computer Science Principles


Test Booklet

AP-CSP-BigIdea3-Assignment

56. Consider the following code segment.

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.

57. Consider the following code segment.

What is displayed as a result of executing the code segment?


(A) 10 20 30 40
(B) 21 30 40 50
(C) 21 40 30 40
(D) 21 40 30 50

AP Computer Science Principles Page 35 of 69


Test Booklet

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.

Number of Steps Number of Steps Number of Steps Number of Steps

List Size

for Algorithm A for Algorithm B for Algorithm C for Algorithm D

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?

Select two answers.

A Algorithm A

B Algorithm B

C Algorithm C

D Algorithm D

59. Consider the following code segment.

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

Page 36 of 69 AP Computer Science Principles


Test Booklet

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 ?

Select two answers.

AP Computer Science Principles Page 37 of 69


Test Booklet

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.

Which of the following is NOT a possible output of this simulation?


(A) The player had 1 bonus round attempts and 1 of them earned extra points.
(B) The player had 2 bonus round attempts and 0 of them earned extra points.
(C) The player had 3 bonus round attempts and 7 of them earned extra points.
(D) The player had 4 bonus round attempts and 3 of them earned extra points.

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.

Page 38 of 69 AP Computer Science Principles


Test Booklet

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 Computer Science Principles Page 39 of 69


Test Booklet

AP-CSP-BigIdea3-Assignment

(A)

(B)

(C)

(D)

Page 40 of 69 AP Computer Science Principles


Test Booklet

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 Computer Science Principles Page 41 of 69


Test Booklet

AP-CSP-BigIdea3-Assignment

67. The figure below shows a circuit composed of two logic gates. The output of the circuit is true.

Which of the following is a true statement about input A?


(A) Input A must be true.
(B) Input A must be false.
(C) Input A can be either true or false.
(D) There is no possible value of input A that will cause the circuit to have the output 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?

Page 42 of 69 AP Computer Science Principles


Test Booklet

AP-CSP-BigIdea3-Assignment

(A)

(B)

(C)

AP Computer Science Principles Page 43 of 69


Test Booklet

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.

Value Before Value After


Variable
Updating Updating
word1 "xylophone" "zebra"
word2 "yarn" "yarn"
word3 "zebra" "xylophone"

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

Page 44 of 69 AP Computer Science Principles


Test Booklet

AP-CSP-BigIdea3-Assignment

71. Consider the following procedure.

Procedure Call Explanation


drawCircle(xPos, yPos, Draws a circle on a coordinate grid with center (xPos, yPos)
rad) and radius rad

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?

Select two answers.

AP Computer Science Principles Page 45 of 69


Test Booklet

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)
}

Page 46 of 69 AP Computer Science Principles


Test Booklet

AP-CSP-BigIdea3-Assignment

72. Consider the following procedures for string manipulation.

Procedure Call Explanation


concat(str1, Returns a single string consisting of str1 followed by str2. For example,
str2) concat("key", "board") returns "keyboard".
Returns the first length characters of str or str if length is greater
prefix(str, than the number of characters in str. For example, prefix("delivery",
length) 3) returns "del" and prefix("delivery", 100) returns
"delivery".

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 Computer Science Principles Page 47 of 69


Test Booklet

AP-CSP-BigIdea3-Assignment

74. Consider the following procedures, which are used to control a device that draws lines on paper.

Procedure Call Explanation


penDown() Places the device’s pen on the paper so that a line is drawn when the device moves
Lifts the device’s pen off of the paper so that no line is drawn when the device
penUp()
moves
goForward(x) Moves the device forward x units
turnRight(x) Rotates the device in place x degrees clockwise (i.e., makes an in-place right turn)

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?

Page 48 of 69 AP Computer Science Principles


Test Booklet

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 Computer Science Principles Page 49 of 69


Test Booklet

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

78. Consider the following procedure.

PROCEDURE doSomething(num1, num2)


{
DISPLAY(num1)
RETURN(num1)
DISPLAY(num2)
}

Consider the following statement.

DISPLAY(doSomething(10, 20))

What is displayed as a result of executing the statement above?


(A) 10 10
(B) 10 20
(C) 10 10 20
(D) 10 20 10

Page 50 of 69 AP Computer Science Principles


Test Booklet

AP-CSP-BigIdea3-Assignment

79. Consider the following code segment.

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?

I. ["blue", "green", "jade", "mauve", "pink"]


II. [5, 5, 5, 5, 6, 7, 8, 8, 8]
III. [10, 5, 3, 2, -4, -8, -9, -12]
(A) I only
(B) III only
(C) I and III only
(D) I, II, and III

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 Computer Science Principles Page 51 of 69


Test Booklet

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?

Page 52 of 69 AP Computer Science Principles


Test Booklet

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 Computer Science Principles Page 53 of 69


Test Booklet

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.

inputVal getRange(min, max, promptString)

Which of the following is a correct implementation of the getRange procedure?


PROCEDURE getRange(min, max, promptString)
{
(A) DISPLAY(promptString)
RETURN(INPUT())
}
PROCEDURE getRange(min, max, promptString)
{
DISPLAY(promptString)
(B) x ← INPUT()
RETURN(x)
}
PROCEDURE getRange(min, max, promptString)
{
DISPLAY(promptString)
x ← INPUT()
REPEAT UNTIL(x ≥ min AND x ≤ max)
(C) {
DISPLAY(promptString)
x ← INPUT()
}
}
PROCEDURE getRange(min, max, promptString)
{
DISPLAY(promptString)
x ← INPUT()
REPEAT UNTIL(x ≥ min AND x ≤ max)
(D) {
DISPLAY(promptString)
x ← INPUT()
}
RETURN(x)
}

Page 54 of 69 AP Computer Science Principles


Test Booklet

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.

myScore updateScore(myScore, myAmount, myLimit)

Which of the following is a correct implementation of updateScore ?

AP Computer Science Principles Page 55 of 69


Test Booklet

AP-CSP-BigIdea3-Assignment

PROCEDURE updateScore(score, amount, limit)


{
score ← score + amount
IF (score > limit)
(A) {
score ← limit
}
}
PROCEDURE updateScore(score, amount, limit)
{
score ← score + amount
IF(score > amount)
(B) {
score ← limit
}
RETURN(limit)
}
PROCEDURE updateScore(score, amount, limit)
{
score ← score + amount
IF(score > limit)
(C) {
score ← limit
}
RETURN(score)
}
PROCEDURE updateScore(score, amount, limit)
{
IF(score = health)
{
score ← score + 10
}
IF(score = food)
{
score ← score + 1
(D) }
IF(score = knowledge)
{
score ← score + 5
}
IF(score > limit)
{
score ← limit
}
}

Page 56 of 69 AP Computer Science Principles


Test Booklet

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?

I. The procedure should take max as an input parameter.


II. The condition in the REPEAT UNTIL block should be changed to count > max.
III. The condition in the REPEAT UNTIL block should be changed to max < 5.
(A) I only
(B) II only
(C) I and II
(D) I and III

AP Computer Science Principles Page 57 of 69


Test Booklet

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.

theList [9, -1, 5, 2, 4, 8]


x theList[index1] + theList[index2]

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

Page 58 of 69 AP Computer Science Principles


Test Booklet

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 Computer Science Principles Page 59 of 69


Test Booklet

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.

Page 60 of 69 AP Computer Science Principles


Test Booklet

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 Computer Science Principles Page 61 of 69


Test Booklet

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?

Page 62 of 69 AP Computer Science Principles


Test Booklet

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 Computer Science Principles Page 63 of 69


Test Booklet

AP-CSP-BigIdea3-Assignment

93. Consider the following code segment.

firstList ["guitar", "drums", "bass"]


secondList ["flute", "violin"]
thirdList []
thirdList firstList
firstList secondList
secondList thirdList

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?

Page 64 of 69 AP Computer Science Principles


Test Booklet

AP-CSP-BigIdea3-Assignment

(A)

(B)

(C)

AP Computer Science Principles Page 65 of 69


Test Booklet

AP-CSP-BigIdea3-Assignment

(D)

Page 66 of 69 AP Computer Science Principles


Test Booklet

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 Computer Science Principles Page 67 of 69


Test Booklet

AP-CSP-BigIdea3-Assignment

(A) Making the code more readable


(B) Making the code run faster
(C) Providing more opportunities for code reuse
(D) Reducing the amount of duplicated code

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

Page 68 of 69 AP Computer Science Principles


Test Booklet

AP-CSP-BigIdea3-Assignment

98. In the following procedure, the parameter str is a string and the parameter num is a number.

PROCEDURE printArgs(str, num)


{
DISPLAY(num)
DISPLAY(str)
DISPLAY(num)
}

Consider the following code segment.

printArgs("**", 1)
printArgs("*", 2)

What is displayed as a result of executing the code segment?


(A) 1 * 1 2 ** 2
(B) 1 ** 1 2 * 2
(C) * 1 * ** 2 **
(D) ** 1 ** * 2 *

99. Consider the following code segment.

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

AP Computer Science Principles Page 69 of 69

You might also like