0% found this document useful (0 votes)
272 views6 pages

AP Computer Science Principles Session1 MCQ

The document contains practice questions for the AP Computer Science Principles exam, focusing on various programming concepts and algorithms. It includes multiple-choice questions related to code execution, program behavior, and search algorithms. Each question is designed to test the understanding of key programming principles and logic.

Uploaded by

sharul.shah2008
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
272 views6 pages

AP Computer Science Principles Session1 MCQ

The document contains practice questions for the AP Computer Science Principles exam, focusing on various programming concepts and algorithms. It includes multiple-choice questions related to code execution, program behavior, and search algorithms. Each question is designed to test the understanding of key programming principles and logic.

Uploaded by

sharul.shah2008
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

2024 AP DAILY: PRACTICE SESSIONS

AP Computer Science Principles


Session 1 – MCQ

1. Consider the code segment below.


Line 1: IF (a = 0)
Line 2: {
Line 3: b ← a + 10
Line 4: }
Line 5: ELSE
Line 6: {
Line 7: b ← a + 20
Line 8: }
Which of the following changes will NOT affect the results when the code segment is executed?

A. Change Line 3 to b ← 10
B. Change Line 3 to a ← b+10
C. Change Line 3 to b ← 20
D. Change Line 3 to a ← b+20

Source: AP Practice Exam; Taken from: APClassroom 1


2. In the program below, y is a positive integer (e.g., 1, 2, 3, …).

What is the value of result after running the program?

A. y+3
B. 3y
C. y3
D. 3y

3. Programs I and II below are each intended to calculate the sum of the integers from 1 to n. Assume
that n is a positive integer (e.g., 1, 2, 3, …).

Source: AP Practice Exam; Taken from: APClassroom 2


Which of the following best describes the behavior of the two programs?

A. Program I displays the correct sum, but program II does not.


B. Program II displays the correct sum, but program I does not.
C. Both program I and program II display the correct sum.
D. Neither program I nor program II displays the correct sum.

4. The question below uses a robot in a grid of squares. The robot is represented as a triangle, which is
initially in the bottom-left square of the grid and facing toward the top of the grid.
Code for the procedure Mystery is shown below. Assume that the parameter p has been assigned a
positive integer value (e.g., 1, 2, 3, …).

Which of the following shows a possible result of calling the procedure?

Source: AP Practice Exam; Taken from: APClassroom 3


A.

B.

C.

D.

Source: AP Practice Exam; Taken from: APClassroom 4


5. The following code segment is intended to set max equal to the maximum value among the integer
variables x , y , and z . The code segment does not work as intended in all cases.

Which of the following initial values for x, y, and z can be used to show that the code segment does not
work as intended?

A. x = 1, y = 2, z = 3
B. x = 1, y = 3, z = 2
C. x = 2, y = 3, z = 1
D. x = 3, y = 2, z = 1

6. In the procedure Mystery below, the parameter number is a positive integer.


PROCEDURE Mystery (number)
{
REPEAT UNTIL (number ≤ 0)
{
number ← number – 2
}
IF (number = 0)
{
RETURN (true)
}
ELSE
{
RETURN (false)
}
}

Source: AP Practice Exam; Taken from: APClassroom 5


Which of the following best describes the result of running the procedure Mystery?

A. The procedure returns true when the initial value of number is 2, and it otherwise returns false.
B. The procedure returns true when the initial value of number is greater than 2, and it otherwise
returns false.
C. The procedure returns true when the initial value of number is even, and it otherwise returns false.
D. The procedure returns true when the initial value of number is odd, and it otherwise returns false.

7. 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.

8. 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.

Source: AP Practice Exam; Taken from: APClassroom 6

You might also like