AP Computer Science Principles Session2 MCQ
AP Computer Science Principles Session2 MCQ
2. The procedure below is intended to display the index in a list of unique names (nameList) where
a particular name (targetName) is found. If targetName is not found in nameList, the code should
display 0.
PROCEDURE FindName (nameList, targetName)
{
index ← 0
FOR EACH name IN nameList
{
index ← index + 1
IF (name = targetName)
{
foundIndex ← index
}
ELSE
{
foundIndex ← 0
}
}
DISPLAY (foundIndex)
}
3. A programmer wrote the program below. The program uses a list of numbers called numList. The
program is intended to display the sum of the numbers in the list.
Which of the following can be used to replace <MISSING CONDITION> in line 4 so that the
program works as intended?
Select two answers.
A. RANDOM(1, 5) = 1
B. RANDOM(1, 5) < 2
C. RANDOM(1, 10) = 2
D. RANDOM(1, 10) < 2
5. A new bank plans to make customer convenience a priority by minimizing the amount of time a
customer waits in line. The bank is considering two options: a single line where the customer at the
front waits for the next available teller, or separate lines for each teller. The bank decides to use a
computer simulation of these two options to determine the average wait time for customers.
Which of the following is NOT true about the bank’s plan?
A. The bank can incorporate other factors, such as the number of tellers, in the simulation.
B. The bank can use the simulation to investigate these two options without causing inconvenience
for customers.
C. The bank may consider new alternatives based on the simulation results.
D. The simulation will not produce usable results because actual customer data are not available.
The programmer wants to reduce the number of operations that are performed when the program is
run. Which change will result in a correct program with a reduced number of operations performed?
A. Every problem can be solved with an algorithm for all possible inputs, in a reasonable amount of
time, using a modern computer.
B. Every problem can be solved with an algorithm for all possible inputs, but some will take more
than 100 years, even with the fastest possible computer.
C. Every problem can be solved with an algorithm for all possible inputs, but some of these
algorithms have not been discovered yet.
D. There exist problems that no algorithm will ever be able to solve for all possible inputs.
8. A certain computer game is played between a human player and a computer-controlled player. Every
time the computer-controlled player has a turn, the game runs slowly because the computer evaluates
all potential moves and selects the best one. Which of the following best describes the possibility of
improving the running speed of the game?
A. The game’s running speed can only be improved if the game is played between two human players
instead of with the computer-controlled player.
B. The game’s running speed might be improved by using a process that finds approximate solutions
every time the computer-controlled player has a turn.
C. The game’s running speed cannot be improved because computers can only be programmed to
find the best possible solution.
D. The game’s running speed cannot be improved because the game is an example of an algorithm
that does not run in a reasonable time.