Question 65

Which of the following can be used to store the string “jackalope” in the string variable animal ? B,C, since the order of the strings within the concat matter. “B” first stores the substing “lope” as animal, then concats “a” and “lope” to get “alope”. Afterwards, it concats “jack” to “alope” to get “jackalope”.

C first stores “jack” as animal, then concats “jack” and “a”, to get “jacka”, and then concats “jacka” to “lope” to get “jackalope”.

Question 58

The following procedure is intended to return true if at least two of the three parameters are equal in value and is intended to return false otherwise.

PROCEDURE AnyPairs (x, y, z)
{
IF (x = y)
{
RETURN (true)
}
ELSE
{
RETURN (y = z)
}
}

The procedure doesn’t have a function for if x=z, so only A wouldn’t be correct.

Question 56

An online game collects data about each player’s performance in the game. A program is used to analyze the data to make predictions about how players will perform in a new version of the game.

The procedure GetPrediction (idNum) returns a predicted score for the player with ID number idNum. Assume that all predicted scores are positive. The GetPrediction procedure takes approximately 1 minute to return a result. All other operations happen nearly instantaneously.

Two versions of the program are shown below.

Version I
topScore 
 0
idList 
 [1298702, 1356846, 8848491, 8675309]
FOR EACH id IN idList
{
score 
 GetPrediction (id)
IF (score > topScore)
{
topScore 
 score
}
}
DISPLAY (topScore)
Version II
idList 
 [1298702, 1356846, 8848491, 8675309]
topID 
 idList[1]
FOR EACH id IN idList
{
IF (GetPrediction (id) > GetPrediction (topID))
{
topID 
 id
}
}
DISPLAY (GetPrediction (topID))

Which of the following best compares the execution times of the two versions of the program?

Version II takes the GetPrediciton twice per id number, and then again at the end, so it would take 11 minutes to complete, which is 5 more min than Version I, which takes the GetPrediction once per id number, and again at the end, resulting in 6 minutes.

Question 52

A biologist wrote a program to simulate the population of a sample of bacteria. The program uses the following procedures.

hours 
 0

startPop 
 InitialPopulation ()

currentPop 
 startPop

REPEAT UNTIL ((hours  24) OR (currentPop  0))

{

currentPop 
 NextPopulation (currentPop)

hours 
 hours + 1

}

DISPLAY (currentPop - startPop)

Which of the following are true statements about the simulation?

The simulation continues until either 24 hours pass or the population reaches 0. The simulation displays the average change in population per hour over the course of the simulation. The simulation displays the total population at the end of the simulation.

Only I is correct, because the simulation continues until either 24 hours pass, or the population reaches 0 because of the line “REPEAT UNTIL ((hours ≥ 24) OR (currentPop ≤ 0))”

II and III are incorrect, because the total populatino is not shown at the end of the simulation, and the simulation displays change in population for the entire course of the simulation.

Question 50

Consider the following algorithms. Each algorithm operates on a list containing n elements, where n is a very large integer.

An algorithm that accesses each element in the list twice An algorithm that accesses each element in the list n times An algorithm that accesses only the first 10 elements in the list, regardless of the size of the list

Which of the algorithms run in reasonable time?

All are correct, since the first would be 2n, the second would be n to the power of n, and the last would just analyze the first 10 integers, so all would be completed in a reasonable time.

Question 47

The procedure BinarySearch (numList, target) correctly implements a binary search algorithm on the list of numbers numList. The procedure returns an index where target occurs in numList, or -1 if target does not occur in numList. Which of the following conditions must be met in order for the procedure to work as intended?

The list has to be in order because BinarySearch works by looking at half of the data, and then narrowing down the pool of possible answers from there.

Question 35

A programmer notices the following two procedures in a library. The procedures do similar, but not identical, things.

Procedure MaxTwo (x, y) returns the greater of its two integer parameters. Procedure MaxThree (x, y, z) returns the greatest of its three integer parameters. Which of the following procedures is a generalization of the MaxTwo and MaxThree procedures?

Max (numlist) returns the greatest of numlist, since it takes the maximum of the integers presented.

Question 29

A person wants to transmit an audio file from a device to a second device. Which of the following scenarios best demonstrates the use of lossless compression of the original file?

“A” would be the correct answer, since lossless compression works by using an algorithm to shrink the data without losing the important data, then sending the unimportant details in an index file, and allowing the second device to fill in to unimportant details.

Question 21

A file storage application allows users to save their files on cloud servers. A group of researchers gathered user data for the first eight years of the application’s existence. Some of the data are summarized in the following graphs. The line graph on the left shows the number of registered users each year. The line graph on the right shows the total amount of data stored by all users each year. The circle graph shows the distribution of file sizes currently stored by all users.

1 megabyte = 1000 kilobytes, so 22+24+17+25 > 75% of the graph

Question 18

The grid below contains a robot represented as a triangle, initially facing right. The robot can move into a white or gray square but cannot move into a black region.

The figure presents a robot in a 5 by 5 grid of squares. The robot is represented by a triangle, which is located in the top leftmost square and is initially facing right. Black squares represent barriers that the robot cannot pass through. The second row contains black shading in the first, second, third, and fourth squares from the left. The third row contains gray shading in the first square, and black shading in the second and fourth squares from the left. The fourth row contains black shading in the second and fourth squares from the left. The code segment below uses the procedure GoalReached, which evaluates to true if the robot is in the gray square and evaluates to false otherwise.

REPEAT UNTIL (GoalReached ())

{

} Which of the following replacements for can be used to move the robot to the gray square? the robot should move forward until it can't move foreward anymore, then rotate right, and repeat. This is shown by the code: REPEAT UNTIL (CAN_MOVE (forward) = false) { MOVE_FORWARD () } ROTATE_RIGHT () This is answer B. ## Reflection I think taking the test helped put into perspective what AP Collegeboard wants from students, and how different it is from what we are doing in class with APIs and databases. It was easier than I had expected, it I could use test-taking strategies to figure out the different legislative acts instead of code. The AP pseudo-code was also a bit confusing, but I think taking the test helped me figure it out as I got used to it. Overall, it was an interesting learning experience, and helped me figure out a lot about robot code and the laws that regulate code.