Font size
WorksheetsAP Computer Science Principles
Total questions: 20
Worksheet time: 10mins
Consider the following code segment. result 𝑟 2 REPEAT 3 TIMES result 𝑟 result * 5 DISPLAY result Which of the following best describes the behavior of the code segment?
The code segment displays the value of 2(5 × 3) by initializing result to 2 and then multiplying result by 3 a total of five times.
The code segment displays the value of 2(5 × 3) by initializing result to 2 and then multiplying result by 5 a total of three times.
The code segment displays the value of 2(5^3) by initializing result to 2 and then multiplying result by 3 a total of five times.
The code segment displays the value of 2(5^3) by initializing result to 2 and then multiplying result by 5 a total of three times.
Which of the following best describes the behavior of the procedure?
It displays nothing if x is negative and displays true otherwise.
It displays nothing if x is negative and displays false otherwise.
It displays true if x is negative and displays nothing otherwise.
It displays true if x is negative and displays false otherwise.
A company that develops educational software wants to assemble a collaborative team of developers from a variety of professional and cultural backgrounds. Which of the following is NOT considered a benefit of assembling such a team?
Collaboration that includes diverse backgrounds and perspectives can eliminate the need for software testing.
Collaboration that includes diverse backgrounds and perspectives can help the team anticipate the needs of a variety of software users.
Collaboration that includes diverse backgrounds and perspectives can help the team avoid bias.
Collaboration that includes diverse backgrounds and perspectives can reflect the strengths of the individual team members.
Which of the following is an advantage of a lossless compression algorithm over a lossy compression algorithm?
A lossless compression algorithm can guarantee that compressed information is kept secure, while a lossy compression algorithm cannot.
A lossless compression algorithm can guarantee reconstruction of original data, while a lossy compression algorithm cannot.
A lossless compression algorithm typically allows for faster transmission speeds than does a lossy compression algorithm.
A lossless compression algorithm typically provides a greater reduction in the number of bits stored or transmitted than does a lossy compression algorithm.
A certain programming language uses 4-bit binary sequences to represent nonnegative integers. For example, the binary sequence 0101 represents the corresponding decimal value 5. Using this programming language, a programmer attempts to add the decimal values 14 and 15 and assign the sum to the variable total. Which of the following best describes the result of this operation?
The correct sum of 29 will be assigned to the variable total.
An overflow error will occur because 4 bits is not large enough to represent either of the values 14 or 15.
An overflow error will occur because 4 bits is not large enough to represent 29, the sum of 14 and 15.
A round-off error will occur because the decimal values 14 and 15 are represented as approximations due to the fixed number of bits used to represent numbers.
A video game character can face toward one of four directions: north, south, east, and west. Each direction is stored in memory as a sequence of four bits. A new version of the game is created in which the character can face toward one of eight directions, adding northwest, northeast, southwest, and southeast to the original four possibilities. Which of the following statements is true about how the eight directions must be stored in memory?
Four bits are not enough to store the eight directions. Five bits are needed for the new version of the game.
Four bits are not enough to store the eight directions. Eight bits are needed for the new version of the game.
Four bits are not enough to store the eight directions. Sixteen bits are needed for the new version of the game.
Four bits are enough to store the eight directions.
A team of researchers wants to create a program to analyze the amount of pollution reported in roughly 3,000 counties across the United States. The program is intended to combine county data sets and then process the data. Which of the following is most likely to be a challenge in creating the program?
A computer program cannot combine data from different files.
Different counties may organize data in different ways.
The number of counties is too large for the program to process.
The total number of rows of data is too large for the program to process.
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. What is the expected score if the player spins the wheel once?
3.25
4
2.75
3
What is the correct option for the code segment that sets score to 10 25% of the time, to 5 25% of the time, and to -1 the remaining 50% of the time?
spin RANDOM 1, 3
spin RANDOM 1, 4
spin RANDOM 1, 6
spin RANDOM 1, 8
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?
"e"
"f\"
"h"
"i"
Assume that the list of numbers nums has more than 10 elements. The program below is intended to compute and display the sum of the first 10 elements of nums. Line 1: i ← 1 Line 2: sum ← 0 Line 3: REPEAT UNTIL (i > 10) Line 4: { Line 5: i ← i + 1 Line 6: sum ← sum + nums[i] Line 7: } Line 8: DISPLAY (sum) Which change, if any, is needed for the program to work as intended?
(A) Lines 1 and 2 should be interchanged.
(B) Line 3 should be changed to REPEAT UNTIL (i ≥ 10).
(C) Lines 5 and 6 should be interchanged.
(D) No change is needed; the program works correctly.
A student wrote the following program to remove all occurrences of the strings "the" and "a" from the list wordList. Line 1: index ← LENGTH (wordList) Line 2: REPEAT UNTIL (index < 1) Line 3: { Line 4: IF ((wordList[index] = "the") OR (wordList[index] = "a")) Line 5: { Line 6: REMOVE (wordList, index) Line 7: } Line 8: } While debugging the program, the student realizes that the loop never terminates. Which of the following changes can be made so that the program works as intended?
Inserting index ← index + 1 between lines 6 and 7
Inserting index ← index + 1 between lines 7 and 8
Inserting index ← index - 1 between lines 6 and 7
Inserting index ← index - 1 between lines 7 and 8
Where could win = true be inserted so that the code segment works as intended?
Between line 6 and line 7
Between line 9 and line 10
Between line 20 and 21
Between line 21 and 22
Which of the following best explains how algorithms that run on a computer can be used to solve problems?
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 reasonable amount of time.
All problems can be solved with an algorithm, but some algorithms might run in an unreasonable amount of time.
Some problems cannot be solved by an algorithm.
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?
x only
y only
x and z only
x, y, and z
Which of the following statements best explains the ability of the network to provide fault tolerance?
The network is considered fault-tolerant because there are redundant paths between each pair of devices.
The network is considered fault-tolerant because it guarantees that no individual component will fail.
The network is not considered fault-tolerant because it relies on physical connections.
The network is not considered fault-tolerant because it provides more paths than are needed.
A program is used to assign processes to each of the processors. Which of the following describes how the program should assign the four processes to optimize execution time?
Assign W and X to one processor and Y and Z to the other processor.
Assign W and Y to one processor and X and Z to the other processor.
Assign W to one processor and X, Y, and Z to the other processor.
Assign all processes to one processor and leave the other processor idle.
21. Processes W, X, Y, and Z need to be assigned to two processors. Which of the following assignments will optimize execution time?
Processes W and X should be assigned to one processor, and processes Y and Z should be assigned to the other processor.
Processes W and Y should be assigned to one processor, and processes X and Z should be assigned to the other processor.
Processes W and Z should be assigned to one processor, and processes X and Y should be assigned to the other processor.
Process Z should be assigned to one processor, and processes W, X, and Y should be assigned to the other processor.
Which of the following best explains how fault tolerance in a network is achieved?
By providing high-bandwidth connections between devices, enabling data packets to be transmitted as quickly as possible
By providing multiple paths between devices, enabling routing to occur even in the presence of a failed component
By providing open network protocols, ensuring that all devices on the network are interacting in a standard way
By providing software to monitor all network traffic, ensuring that data packets are sent and received in the proper order
The message is broken into packets that are transmitted in a specified order. Each packet must be received in the order it was sent for the message to be correctly reassembled by the recipient’s device. (A) The message is broken into packets that are transmitted in a specified order. Each packet must be received in the order it was sent for the message to be correctly reassembled by the recipient’s device. (B) The message is broken into packets. The packets can be received in any order and still be reassembled by the recipient’s device. (C) The message is broken into two packets. One packet contains the data to be transmitted and the other packet contains metadata for routing the data to the recipient’s device. (D) The message is transmitted as a single file and received in whole by the recipient’s device.
The message is broken into packets that are transmitted in a specified order. Each packet must be received in the order it was sent for the message to be correctly reassembled by the recipient’s device.
The message is broken into packets. The packets can be received in any order and still be reassembled by the recipient’s device.
The message is broken into two packets. One packet contains the data to be transmitted and the other packet contains metadata for routing the data to the recipient’s device.
The message is transmitted as a single file and received in whole by the recipient’s device.
