wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Code.org Algorithms AP CSP

Total questions: 85

Worksheet time: 1hrs 18mins

Name
Class
Date
1.

This is known as a precise sequence of instructions for processes that can be executed by a computer and are implemented using programming languages.

a)

Function

b)

Parameter

c)

Algorithm

d)

Command

2.

Which of the following is FALSE regarding algorithms?

a)

Option 1: Different algorithms can be developed to solve the same problem

b)

Option 2: Different code can never be written to implement the same algorithm

c)

Both Option 1 and 2 are true

d)

Both Option 1 and 2 are false

3.

Every algorithm can be constructed on using:

a)

Sequencing

b)

Selection

c)

Iteration

d)

Questions

4.

When your programming is achieving some desired outcome while minimizing wasted effort or resources, we would say that its:

a)

Top Notch

b)

Comparable

c)

Efficient

d)

Problematic

5.

Looking at Lines 3 and 5 above, the "IF" statements in these particular parts of the algorithm are constructed with:

a)

Selection

b)

Iteration

c)

Sequencing

6.

Placing Lines 1-9 of your algorithm in a particular order shows which of the following is important?

a)

Sequencing

b)

Selection

c)

Iteration

7.

Looking at the image above, looping (through iteration) can be seen in which of the following lines of this algorithm?

a)

Line 2

b)

Line 7

c)

Line 3

d)

Line 9

8.

The ordered steps in a program.

a)

Sequence

b)

If...Then...Else

c)

Conditional

d)

Value

9.

________________ is a sequence of instructions (or algorithm) written in a language or code that a computer can understand and put into action. Must be accurate to be correct.

a)

Procedure

b)

Algorithm

c)

Program

d)

Loop/ Repeat

10.

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.

11.
A red triangle is pictured below in a grid of squares. It is currently facing upward, and can only move using the MoveTriangle procedure, shown below. The triangle can move onto white and gray squares, but not onto the black squares.
PROCEDURE MoveTriangle (numMoves, numTurns)
{ 
REPEAT
numMoves TIMES   

MOVE_FORWARD() 
}
 
REPEAT numTurns TIMES 
{   
TURN_RIGHT() 
}
}
Which of the following instructions will get the red triangle to the gray square?
a)
 
MoveTriangle (1, 1) MoveTriangle (1, 1) MoveTriangle (3, 1) MoveTriangle (3, 0)
b)
MoveTriangle (4, 1)
MoveTriangle (4, 0)
c)
MoveTriangle (1, 1)
MoveTriangle (1, 3)
MoveTriangle (3, 1)
MoveTriangle (3, 0)
 
d)
MoveTriangle (1, 1)
MoveTriangle (1, 3)
MoveTriangle (3, 3)
MoveTriangle (3, 0)
12.
__________ means to repeat in order to achieve, or get closer to, a desired goal.
a)
Sequence
b)
Iterate
c)
Select
13.
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
14.
Putting commands in correct order so computers can read the commands is 
a)
algorithms
b)
selection
c)
sequencing
15.
What is the correct definition of an algorithm?
a)
An algorithm is a step by step instructions to solve a problem.
b)
An algorithm is a process of baking bread.
c)
An algorithm is a software used to compute numbers.
d)
An algorithm is the process of breaking problems.
16.
What is the difference between a flowchart and pseudocode? 
a)
A flowchart is diagramatic whilst pseudocode is written in a programming language (eg. Pascal or Java) 
b)
A flowchart is textual but pseudocode is diagrammatic 
c)
A flowchart is a diagrammatic description of an algorithm whilst pseudocode is a textual description of an algorithm 
d)
A flowchart and pseudocode are the same thing 
17.

Writing a for-loop in Javascript is an example of what coding principle?

a)

sequencing

b)

sorting

c)

iteration

d)

selection

e)

rotation

18.

Writing an if-else statement in Javascript is an example of what coding principle?

a)

sequencing

b)

sorting

c)

iteration

d)

selection

e)

rotation

19.

An algorithm with an efficiency rating of

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

would be considered 

a)

reasonable time

b)

unreasonable time

20.

An algorithm with an efficiency rating of

n2n^2 or  n3n^3  or  n20n^{20}  

would be considered 

a)

reasonable time

b)

unreasonable time

21.

A BINARY SEARCH looks for a certain name in a list of sixteen names. What is the most possible number of places it will have to check?

a)

1

b)

2

c)

4

d)

8

e)

16

22.

A LINEAR SEARCH looks for a certain name in a list of sixteen names. What is the most possible number of places it will have to check?

a)

1

b)

16

c)

4

d)

15

e)

8

23.

A BINARY SEARCH looks through a list named studentList finds an what it was searching for in the first spot it looked. Where was it?

a)

at index 0

b)

at index studentList.length / 2

c)

at index studentList.length

24.

A LINEAR SEARCH looks through a list named studentList finds an what it was searching for in the first spot it looked. Where was it?

a)

at index 0

b)

at index studentList.length/2

c)

at index studentList.length

25.

A finite list of instructions to solve a problem is called

a)

an algorithm

b)

a program

c)

the solution

d)

the answer

e)

the code

26.

If 7 people wait in line for the drinking fountain there would be ____ different orders.

a)

7

b)

49

c)

14

d)

5040

e)

5 million

27.

When working with 3 letters of the alphabet, they can be rearranged in _____ different orders.

a)

3

b)

5

c)

6

d)

9

e)

27

28.

To calculate the different orders that you could visit 10 cities using your calculator you would type:

a)

10*10

b)

10^10

c)

10!

d)

10+10

e)

log 10

29.

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

30.

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

31.

2 students write code that works to solve a problem in JavaScript.


Both students' code works.


What is the most significant difference that could still exist between the 2 students' code?

a)

style

b)

comments

c)

variable names

d)

efficiency

e)

length of code

32.

All problems can be solved using an algorithm.

a)

TRUE

b)

FALSE

33.

Which of these, would work the fastest to find the number 10 in the list below?


[ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13 ]

a)

linear search

b)

perimeter search

c)

straight search

d)

binary search

e)

split seach

34.

Which of these, would work the fastest to find the number 7 in the list below?


[ 3, 7, 8, 15, 2, 4, 9, 10, 6, 5, 11, 1, 12, 13 ]

a)

linear search

b)

perimeter search

c)

straight search

d)

binary search

e)

split seach

35.

Which of these, given a list with 100 elements would look at index 50 first, and the decide to look at index 25 or index 75 next?

a)

linear search

b)

perimeter search

c)

straight search

d)

binary search

e)

split seach

36.

Which of these, given a list with 100 elements would look at index 0, then index 1, then index 2 ....

a)

linear search

b)

perimeter search

c)

straight search

d)

binary search

e)

split seach

37.

Using an "if" in your code is referred to in APCSP as:

a)

iteration

b)

selection

c)

sequencing

d)

sorting

e)

prioritizing

38.

Using a loop in your code is referred to in APCSP as:

a)

iteration

b)

selection

c)

sequencing

d)

sorting

e)

prioritizing

39.

Getting your code to execute commands in the correct order is called:

a)

iteration

b)

selection

c)

sequencing

d)

sorting

e)

prioritizing

40.

Finite means:

a)

having a countable amount

b)

being picky

c)

completing a program

d)

terminating your code

e)

finishing an algorithm

41.

A step by step process to solve a problem is called:

a)

problem solving

b)

an algorithm

c)

code

d)

a program

e)

instructions

42.

In JavaScript you would implement code ITERATION by:


(CHOOSE ALL CORRECT ANSWERS)

a)

writing a for-loop

b)

writing a while loop

c)

making a list

d)

writing an if statement

e)

writing an if-else statement

43.

In JavaScript you would implement code SELECTION by:


(CHOOSE ALL CORRECT ANSWERS)

a)

writing a for-loop

b)

writing a while loop

c)

making a list

d)

writing an if statement

e)

writing an if-else statement

44.

If it is AFTER 7am, what do you need to do?

a)

Take the bus

b)

Take the subway

c)

Check the time

d)

Leave home

45.

You are at the yellow arrow, pointing in the direction indicated. How would you move to fill in the 2 black squares?

a)

Straight, Turn right, Straight x 1, Fill Square, Straight x 2, Turn left, Straight x 1, Fill Square

b)

Straight x 2, Turn right, Straight x 1, Fill Square, Straight x 2, Turn left, Straight x 1, Fill Square

c)

Straight x 2, Turn right, Straight x 1, Fill Square, Straight x 2, Turn right, Straight x 1, Fill Square

d)

Straight x 2, Turn right, Straight x 1, Fill Square, Straight x 2, Turn left, Straight x 2, Fill Square

46.

What must be true before performing a binary search?

a)

The elements must be sorted.

b)

It can only contain binary values.

c)

The elements must be some sort of number (i.e. int, double, Integer)

d)

There are no necessary conditions.

47.

True or false: If an array is already sorted, Linear Search / Sequential Search is more efficient than Binary Search.

a)

True

b)

False

48.

Given this list:


1, 2, 4, 5, 6, 7, 8, 12, 14, 21, 22, 42, 53


How many comparisons are required to find 42 using the Binary Search?

a)

3

b)

2

c)

10

d)

5

49.

Given this array:


1, 2, 4, 5, 6, 7, 8, 12, 14, 21, 22, 42, 53


How many comparisons are required to find 42 using the Linear Search / Sequential Search?

a)

3

b)

2

c)

12

d)

5

50.

BMO the robot is programming a new game called “Open the box!” You give him a number and he tries to open a numbered box. He’s using Binary Search to accomplish this. Unfortunately, the boxes are not sorted. They are in the following order:


1, 3, 6, 9, 14, 10, 21


Which box can NEVER be found using binary search?

a)

9

b)

6

c)

14

d)

10

51.

We are searching for a number key in a sorted list that has n elements. Under what circumstances will Linear Search / Sequential Search be more efficient than Binary Search?

a)

key is the last element in the array

b)

key is in the middle of the array

c)

n is very large

d)

key is the first element in the array

e)

key does not exist in the array

52.

What is the largest number of comparisons needed to perform a binary search on an array with 42 elements?

a)

2

b)

5

c)

6

d)

41

e)

42

53.

Identify the description of a linear search.

a)

Put the elements in order, check each item in turn

b)

Order elements,compare middle value,split list in order&loop

c)

Elements do not need to be in order, check each item in turn

d)

Randomize data, compare middle value, split list in order & loop

54.

Identify the description of a binary search.

a)

Put the elements in order, check each item in turn

b)

Order elements,compare middle value,split list in order&loop

c)

Elements do not need to be in order, check each item in turn

d)

Randomize data, compare middle value, split list in order & loop

55.

A linear search is to be performed on the list:

12, 6, 8, 1, 3


How many comparisons would it take to find the number 1?

a)

1

b)

2

c)

3

d)

4

56.

A binary search is to be performed on the list:

3, 5, 9, 10, 23


How many comparisons would it take to find the number 9?

a)

1

b)

3

c)

4

d)

It can't find the number 9

57.
Which of the following is an example of the use of heuristics?
a)
Trying every possible combination of letters when unscrambling a word
b)
Considering each possible move when playing chess
c)
Using the formula “area=length x width” to find the area of a rectangle
d)
Playing chess using a defensive strategy that has often been successful for you
58.
A problem solving strategy that often includes a formula and guarantees an answer to the problem is a(n)
a)
subgoal
b)
prototype
c)
Algorithm
d)
Heurisitc
59.

What is the third step using Binary Search to look for the number 31 in this list: 1, 3, 4, 8, 10, 11, 16, 28, 31, 32, 45, 49, 51, 69, 75

a)

Compare the number 28 to the given number

b)

Compare the number 8 to the given number

c)

Compare the number 32 to the given number

d)

Compare the number 49 to the given number

60.

Which of the following would be considered unreasonable?

a)

3^n

b)

3n

c)

n^3

d)

n^30

61.

Which of the following is FALSE regarding undecidable problems and unreasonable time algorithms?

a)

Unreasonable time algorithms can never be ran and will never produce a correct solution

b)

Undecidable problems are a type of problem for which it has been proven that there simply is no algorithm that will always produce a correct result

c)

Unreasonable problems grow in size so quickly, even for small inputs, that it is usually unreasonable to run that algorithm

d)

With regards to undecidable problems, the issue isn't simply that it takes a long time, but that it is demonstrably impossible to write such an algorithm.

62.

An algorithm was initially written sequentially. Later it was determined that a parallel solution was possible and so the algorithm rewritten. The times to run each version of the algorithm are included in the table above. What is the speedup of this parallel solution?

a)

.5

b)

2

c)

120

d)

40

63.

Parallel algorithms typically will be faster than sequential algorithms

a)

True

b)

False

64.

Which of the following is FALSE on why the speedup of a parallel algorithm will eventually reach some limit?

a)

Parallel algorithms will only have portions of the algorithm that are parallel with no sequential portions

b)

Running the algorithm on more computers can speed up the parallel portions

c)

Sequential portions are not sped up by adding more computers

d)

The sequential portion of the algorithm will eventually put a limit on the overall speedup

65.

Adding additional parallel processes will always lead to the same amount of speedup

a)

True

b)

False

66.

Because some portions are always still sequential, the benefits of adding more processors will go down and eventually the speedup reaches a limit

a)

True

b)

False

67.

Which of the following is FALSE regarding the "Traveling Salesman Problem" discussed in Lesson 4?

a)

For every new house to visit, the number of options for possible paths doubles

b)

It can be solved with an algorithm, which checks each possible option.

c)

The Traveling Salesman is an Optimization Problem, NOT a Decision Problem

d)

It involves determining what is the shortest or most efficient path

68.

Under which of the following conditions is it most beneficial to use a heuristic approach to solve a problem?

a)

When the problem can be solved in a reasonable time and an approximate solution is acceptable

b)

When the problem can be solved in a reasonable time and an exact solution is needed

c)

When the problem cannot be solved in a reasonable time and an approximate solution is acceptable

d)

When the problem cannot be solved in a reasonable time and an exact solution is needed

69.

Parallel computing consists of both a parallel portion that is shared and ___________________ portion.

a)

Distributed

b)

Sequential

c)

Unreasonable

d)

Reasonable

70.

To compute a speedup calculation:

a)

Divide Parallel Time by Sequential Time

b)

Subtract Sequential Time by Parallel Time

c)

Substract Parallel Time by Sequential Time

d)

Divide Sequential Time by Parallel Time

71.

Some portions of your algorithm can’t be made parallel. Each additional processor helps a little less.

a)

True

b)

False

72.

More and more processors can help improve the speedup calculation in that it's limitless

a)

True

b)

False

73.

An algorithm was initially written sequentially. Later it was determined that a parallel solution was possible and so the algorithm rewritten. The times to run each version of the algorithm are included in the table above. What is the speedup of this parallel solution?

a)

.75

b)

1.33

c)

300

d)

2

74.

Parallel Programs:

a)

typically are slower programs than Sequential

b)

cannot be slowed down even if only one of many devices is slow

c)

can improve every single time more processors are added

d)

are often times the fastest option, but there is a limit

75.
How many linear searches will it take to find the value 7 in the list [1,4,8,7,10,28]?
a)
2
b)
3
c)
4
d)
5
76.
On average, which searching algorithm is more efficient?
a)
Binary Search
b)
Linear Search
77.
How many binary searches will it take to find the value 10 in the list [1,4,9,10,11]?
a)
0
b)
1
c)
2
d)
3
78.
Which of the following is the best description of the linear search algorithm?
a)
Put the elements in order, then go through them one by one until target is found or the end of the list is reached.
b)
Put the elements in order, compare with the middle value, if not the target: continue to the left or right of the middle and repeat. 
c)
Elements do not need to be in order. Go through them one by one until target is found or the end of the list is reached.
d)
Elements do not need to be in order, compare with the middle value, if not the target: continue to the left or right of the middle and repeat. 
79.
What does a linear search do?
a)
Looks at the first item of data, then each one in turn, until it finds the data item requested
b)
Organises the data into alphabetical order
c)
Splits the data until the requested data is found
80.
What does a binary search do?
a)
Looks at the first item of data, then each one in turn, until it finds the data item requested
b)
Converts all the data into binary
c)
Takes the data and splits it in half repeatedly until it finds the data item requested
81.
What is an advantage of a linear search?
a)
It is very quick
b)
It only works with ordered lists
c)
It is a simple algorithm
82.
Which search algorithm would be best to use with ordered data?
a)
A binary search
b)
Either binary search or a linear search
c)
A linear search
83.
What is the biggest disadvantage of a binary search?
a)
It is slow
b)
It can only be used if the data is sorted into an order
c)
It takes the data and keeps dividing it in half until it finds the item it is looking for
84.

How many searches will it take to find 10 in [1,3,5,7,10,12,15] using BINARY search?

a)

3

b)

4

c)

5

d)

6

85.

Which algorithm uses a divide and conquer approach?

a)

Linear Search

b)

Binary Search