wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

APCSP AP Test Review

Total questions: 40

Worksheet time: 32mins

Name
Class
Date
1.

An algorithm will be used to calculate the difference between the smallest and largest values in a list. For the list of [10, 3, 5, 6], it should calculate a difference of 7.


There are two proposals for the algorithm:


Algorithm 1: Set minVal to the first value in the list and maxVal to the last value in the list. Iterate through each number in the list. If the number is greater than maxVal, store it in maxVal. If the number is less than minVal, store it in minVal. After loop, set maxDiff to the difference between maxVal and minVal.


Algorithm 2: Set minVal to 1000 and maxVal to 0. Iterate through each number in the list. If the number is greater than maxVal, store it in maxVal. If the number is less than minVal, store it in minVal. After loop, set maxDiff to the difference between maxVal and minVal.


Which of these statements are true about these algorithms?

I. Algorithm 1 does not work on lists where the smallest value is at the start of the list or the largest value is at the end of the list.

II. Algorithm 2 does not work on lists that contain all negative numbers or all numbers over 1000.

Choose 1 answer:


Choose 1 answer:

a)

I

b)

II

c)

I and II

d)

Neither I or II

2.

"Aba speak" is a game invented by school children to disguise what they're speaking.

When speaking, they transform each word following this algorithm:


For each letter in word:

If letter is vowel:

Add "b" after

Add that letter after "b"


Following that algorithm, how would they transform the word "avocado"?

Choose 1 answer:


Choose 1 answer:

a)

abvobcabdob

b)

avabocabadabo

c)

abavobocabadobo

d)

abavbvobocbcabadbdobo

e)

abavobacabadoba

3.

Determine what is printed by the following code.


values ⬅ [5, 6, 7, 0, 3, 3]

baz ⬅ 0

FOR EACH value IN values

{

if( value ≥ 7 )

{

baz ⬅ baz + 1

}

}

DISPLAY( baz )

a)

1

b)

0

4.

Determine what is printed by the following code.


list ⬅ [11, 2, 8, 6, 4, 2, 5, 6, 9, 12]

fizz ⬅ 0

thud ⬅ 0

FOR EACH item IN list

{

if( item MOD 3 = 2 )

{

thud ⬅ thud + 1

}

fizz ⬅ fizz + 1

}

DISPLAY( thud / fizz )

a)

0

b)

1

c)

0.5

d)

5/10

5.

A programmer for a weather website needs to display the proportion of days with freezing temperatures in a given month.


Their algorithm will operate on a list of temperatures for each day in the month. It must keep track of how many temperatures are below or equal to 32. Once it's done processing the list, it must display the ratio of freezing days over total days.


Which of these correctly expresses that algorithm in pseudocode?

a)

numFreezing ← 0

numDays ← 0

FOR EACH temp IN temps {

IF (temp ≤ 32) {

numFreezing ← numFreezing + 1

}

numDays ← numDays + 1

DISPLAY(numFreezing/numDays)

}

b)

numFreezing ← 0

numDays ← 0

FOR EACH temp IN temps {

IF (temp ≤ 32) {

numFreezing ← numFreezing + 1

}

numDays ← numDays + 1

}

DISPLAY(numFreezing/numDays)

c)

numFreezing ← 0

numDays ← 0

FOR EACH temp IN temps {

IF (temp < 32) {

numFreezing ← numFreezing + 1

}

numDays ← numDays + 1

}

DISPLAY(numFreezing/numDays)

d)

numFreezing ← 0

numDays ← 0

FOR EACH temp IN temps {

IF (temp ≤ 32) {

numFreezing ← numFreezing + 1

numDays ← numDays + 1

}

}

DISPLAY(numFreezing/numDays)

6.

A programmer is deciding between using a linear or binary search to find a target value in a sorted list. Which of the following is true?

a)

In all cases, a binary search of a sorted list requires fewer comparisons than a linear search.

b)

Generally, the advantage of using a binary search over a linear search increases as the size of the list increases.

c)

A linear search will generally run faster than a binary search because a linear search requires fewer lines of code to implement.

d)

Using a linear search is preferable to using a binary search if there is a chance that the target may not be found in the list.

7.

An algorithm has been developed to compute the sum of all the elements in a list of integers.


Which of the following programming structures must be added to the existing algorithm so that the new algorithm computes the sum of only the even integers in the list?

a)

Iteration

b)

Searching

c)

Selection

d)

Sequencing

8.

An algorithm will be used to identify the maximum value in a list of one or more integers. Consider the two versions of the algorithm below.


Algorithm I : Set the value of a variable max to − 1. Iterate through the list of integer values. If a data value is greater than the value of the variable max, set max to the data value.


Algorithm II : Set the value of a variable max to the first data value. Iterate through the remaining values in the list of integers. If a data value is greater than the value of the variable max, set max to the data value.


Which of the following statements best describes the behavior of the two algorithms?

a)

Both algorithms work correctly on all input values.

b)

Algorithm I always works correctly, but Algorithm II only works correctly when the maximum value is not the first value in the list.

c)

Algorithm II always works correctly, but Algorithm I only works correctly when the maximum value is greater than or equal to − 1.

d)

Neither algorithm will correctly identify the maximum value when the input contains both positive and negative input values.

9.

Central High School keeps a database of information about each student, including the numeric variables numberOfAbsences and gradePointAverage. The expression below is used to determine whether a student is eligible to receive an academic award.


(numberOfAbsences ≤ 5) AND (gradePointAverage > 3.5)


Which of the following pairs of values indicates that a student is eligible to receive an academic award?

a)

numberOfAbsences = 3, gradePointAverage = 3.5

b)

numberOfAbsences = 5, gradePointAverage = 3.8

c)

numberOfAbsences = 6, gradePointAverage = 3.4

d)

numberOfAbsences = 6, gradePointAverage = 3.6

10.

Consider the following code segment, which uses the variables r, s, and t.

r ← 1

s ← 2

t ← 3

r ← s

s ← t


DISPLAY (r)

DISPLAY (s)

a)

11

b)

12

c)

23

d)

32

11.

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

12.

A programmer completes the user manual for a video game she has developed and realizes she has reversed the roles of goats and sheep throughout the text.


Consider the programmer’s goal of changing all occurrences of “goats” to “sheep” and all occurrences of “sheep” to “goats.” The programmer will use the fact that the word “foxes” does not appear anywhere in the original text.


Which of the following algorithms can be used to accomplish the programmer’s goal?

a)

First, change all occurrences of “goats” to “sheep.”

Then, change all occurrences of “sheep” to “goats.”

b)

First, change all occurrences of “goats” to “sheep.”

Then, change all occurrences of “sheep” to “goats.”

Last, change all occurrences of “foxes” to “sheep.”

c)

First, change all occurrences of “goats” to “foxes.”

Then, change all occurrences of “sheep” to “goats.”

Last, change all occurrences of “foxes” to “sheep.”

d)

First, change all occurrences of “goats” to “foxes.”

Then, change all occurrences of “foxes” to “sheep.”

Last, change all occurrences of “sheep” to “goats.”

13.

Determine what is printed by the following code.


numbers ⬅ [7, 4, 1, 6, 4, 11, 3]

baz ⬅ 0

FOR EACH value IN numbers

{

if( value < 3 )

{

baz ⬅ baz + 1

}

}

DISPLAY( baz )

a)

0

b)

1

c)

none of the above

14.

Determine what is printed by the following code.


numbers ⬅ [8, 5, 7, 1, 12, 12]

fred ⬅ 0

FOR EACH number IN numbers

{

if( number MOD 2 = 0 )

{

fred ⬅ fred + 1

}

}

DISPLAY( fred )

a)

3

b)

2

c)

1

d)

0

15.

for (var i = 10; i > 5; i--){

console.log ("p"); }


How many times will "p" be printed?

a)

10

b)

5

c)

6

d)

infinite loop

16.
In programming, an expression that evaluates to True or False. 

a)
Abstraction
b)
Boolean Expression
c)
Aggregate Expression
d)
None of the above
17.
Any sequence of characters between quotation marks (ex: "hello", "42", "this is a string!").
a)
Selection
b)
String
c)
Summary
d)
Protocol
18.
The equality operator is used to compare two values, and returns a Boolean (true/false). 
a)
=
b)
==
c)
<=
d)
>=<
19.
Which are examples of Boolean operators?
a)
AND, OR and NOT
b)
Greater than (>), less than (<) and equal to (=)
c)
Multiplication (*), subtraction (-), addition (+) and division (/)
d)
Picking random numbers
20.

Based on the following, determine whether each expression is TRUE or FALSE


var score= 80;


(score != 90) && (score > 70)

a)

True

b)

False

21.

What 2 items below make your code easier to read and manage/edit later?

a)

good variable names

b)

testing your code often

c)

write perfect code the first time

d)

comments

22.

Determine what is printed by the following code.


values ⬅ [5, 6, 7, 0, 3, 3]

baz ⬅ 0

FOR EACH value IN values

{

if( value ≥ 7 )

{

baz ⬅ baz + 1

}

}

DISPLAY( baz )

a)

1

b)

0

23.

Consider the following code segment, which uses the variables r, s, and t.

r ← 1

s ← 2

t ← 3

r ← s

s ← t


DISPLAY (r)

DISPLAY (s)

a)

11

b)

12

c)

23

d)

32

24.

Determine what is printed by the following code.


numbers ⬅ [7, 4, 1, 6, 4, 11, 3]

baz ⬅ 0

FOR EACH value IN numbers

{

if( value < 3 )

{

baz ⬅ baz + 1

}

}

DISPLAY( baz )

a)

0

b)

1

c)

none of the above

25.

One data point that is stored in a list. It is a single part of a larger group.

a)

Element

b)

Index

c)

List

26.

A data structure that stores one or more similar types of values in a single value. A collection of individual values that are related.

a)

Element

b)

Index

c)

List

27.

Identifies a value’s unique position on a list. In SNAP & on the APCSP exam the first item is stored at index 1.

a)

Element

b)

Index

c)

List

28.

Performing the same operation on each item of the list, sequentially.

a)

Traverse

b)

Remove/Delete

c)

Append

29.

What is displayed from this code?

a)

1,2,3,4,5

b)

Nothing, it won't run

c)

1, 2, 4, 8

d)

1, 2, 4

30.

A student wants to create an algorithm that can determine, given any program and program input, whether or not the program will go into an infinite loop for that input. The problem the student is attempting to solve is considered an undecidable problem. Which of the following is true?

a)

It is possible to create an algorithm that will solve the problem for all programs and inputs, but the

algorithm can only be implemented in a low-level programming language.

b)

It is possible to create an algorithm that will solve the problem for all programs and inputs, but the

algorithm requires simultaneous execution on multiple CPUs.

c)

It is possible to create an algorithm that will solve the problem for all programs and inputs, but the

algorithm will not run in reasonable time.

d)

It is not possible to create an algorithm that will solve the problem for all programs and inputs.

31.
__________ means to repeat in order to achieve, or get closer to, a desired goal.
a)
Sequence
b)
Iterate
c)
Select
32.
A generic term for a type of programming statement (usually an if-statement) that uses a Boolean condition to determine, or select, whether or not to run a certain block of statements is ______.
a)
Iteration
b)
Selection
c)
Sequencing
33.
Putting commands in correct order so computers can read the commands is 
a)
algorithms
b)
selection
c)
sequencing
34.

An algorithm with an efficiency rating of

2n2^n or  3n3^n  or  n!n!  

would be considered 

a)

reasonable time

b)

unreasonable time

35.

The action of doing something over and over again.

a)

Looping

b)

Bugging

c)

Programming

36.

If the length of the list is 100 times longer, the search will probably on average take 100 times longer to complete.


This is true using a:

a)

linear search

b)

binary search

37.

If the length of the list is 100 times longer, the search will might on average only take 7-8 times longer to complete.


This is true using a:

a)

linear search

b)

binary search

38.
Convert 85 into Hexadecimal
a)
01010101
b)
55
c)
5A
d)
A5
39.
Binary 1111
Hex = ?
a)
14
b)
F
c)
15
d)
E
40.

A unit of data that is eight binary digits long. Bytes are often used to represent a character such as a letter, number, space

a)

Bit

b)

Byte

c)

Block