Algorithm Questions in AP CSP Exam | Alps Academy

student with ap csp exam prep

AP Computer Science Principles Course Exam Preparation

In this series of articles we will explain some of the sample questions that are provided to help AP CSP students with their exam preparation.

Algorithms

This article focuses on the AP CSP exam questions related to algorithms.

Although there are many areas of interest related to algorithms, here we focus on the questions posed in the sample practice exams. This includes the design with sequence, selection and iteration, and types of algorithms such as binary search and heuristics.

The AP CSP course did cover algorithm efficiency but these questions are rare in the sample questions. There is the binary search question below in the types of algorithms section.

Sample Exam Questions

We have taken examples from the sample questions from the two practice question sets from 2021 and from previous practice exercises provided by the college board.

Although it does not mean these are going to be in the exam, it is assumed that the primary areas of computing, programming, networks, data and algorithms will form most of the CSP exam.

These articles will present and explain questions and answers in these areas.

What type of programming questions will be in the CSP exam?

We don’t know. But we do know that during the AP CSP course we have learn about types of algorithms and design.

Practice Exam questions

Read the questions and check your answer with the explanation below. We want to help everybody so if you think the question is easy then move on to the next question without reading the solution if you wish.

Some questions have more than one answer – these multiple answer questions are also in the AP CSP exam.

algorithm design

What does iteration with computer science loops mean?

  • A. Executing code once
  • B. Repeating a block of code until a condition is met
  • C. Duplicating a section of code multiple times in a program
  • D. Identifying the error condition

To iterate is to go through a loop, to repeat, every time you run the code within a loop it is called an iteration.

So A is not a loop, B looks good for a while loop, C is duplication not repetition, and D is just wrong.

Answer: B

How many times do FOR EACH loops run with lists?

  • A. Once
  • B. Until the index for the list is 0
  • C. For the LENGTH of the list
  • D. Until the user types STOP

For each loops are for loops in languages like python and Java. We can use them to iterate over a list so C is correct.

Once is not a list, B is only true if you are going through a list backwards, and D is incorrect.

Answer: C

Which type(s) of statement is needed to find all records in a list that are positive?

  • A. Sequential and iterative
  • B. Selection and sequential
  • C. Selection
  • D. Iterative and selection

All records in a list would require a loop such as iteration. Answers A  and D include iterative therefore we need to choose between sequential and selection.

Choosing the records that are positive would require selection. So not A.

Answer: D

types of algorithms

Why is a binary search the most effective way to search a sorted data set?

  • A. The item searched for bubbles to the beginning of the data set after one pass
  • B. It uses machine learning with each pass of the data to learn where the data is located in the file to speed up the search process
  • C. It eliminates half the data set with each iteration of the search
  • D. It merges sections of data to only have to search one section with each iteration

Why is a binary search efficient? Lets look at the options.

Looks for bubbles? Don’t get that. It does not use machine learning but it does remove half the data set when wrong (e.g. higher or lower) so that is why it is efficient.

It doesn’t merge anything. Perhaps the bubble and merge are words used for algorithms to try to confuse you. But C is correct.

Answer: C

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 approximation 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 approximation solution is acceptable
  • D. When the problem cannot be solved in a reasonable time and an exact solution is needed

We think of using a heuristic approach when we can’t solve something easily and just want to use a rule to somehow get to the answer in a reasonable manner.

Think, if I go in the right direction I will get to my destination.

A looks possible, B seems more easy, C also seems reasonable, and by D it is getting confusing. We are looking for an approximate solution so A or C.

So if it be solved in a reasonable time the you could use a simple algorithm or brute force, every option, so we want “cannot be solved in a reasonable time”.

Answer: C

What must be true for a binary search to work correctly?

  • even amount of data
  • no duplicates
  • data is sorted
  • data is unsorted

coding algorithms

Each of the following can make an algorithm more readable except?

  • A. Well-named variables and procedures
  • B. Consistent formatting within the code
  • C. Procedures that have one purpose
  • D. Minimizing the use of loops so the program flow will be clearer

Which of these options is not a way of making the code more readable? More readable is true for A definitely, B also. C is no always true but it does help make the code easier to understand.

Option D might be an optimization concern but not readability. D is our answer.

Answer: D

An algorithm finds the smallest (small) number in a list of integers (num). Which code does it use?

a)	if (small < num){
	num = small
}
b) if (small < num){
	small = num
}
c) if (small > num){
	num = small
}
d) if (small > num){
	small = num
}

Each of the following can make an algorithm more readable, except?

  • procedures with one purpose
  • relevant comments
  • well-named variables
  • computer-created font

More AP CSP exam practice questions

This is the fourth of a series of articles that take questions from the sample practice exams.

The first article was about computing questions. Click on the following link to see this article: Computing Questions in the Computer Science Principles AP CSP Exam

The second article was about network questions. Click on the following link to see this article: Network Questions in the Computer Science Principles AP CSP Exam

The third article was about programming questions. Click on the following link to see this article: Programming Questions in the Computer Science Principles AP CSP Exam

If you wish to see an overview of the sample questions related to the AP CSP exam, please visit the following article:

Ultimate Guide to AP Computer Science Principles Exam Questions

AP CSP exam webpage

For all courses, articles and information relating to the AP Computer Science Principles Exam, see our dedicated web page. Click the following link to visit this webpage: AP CSP Exam webpage

Big Ideas exam practice questions

There are also practice questions grouped by the ‘big ideas’ that are here in pdf format.

So, if you want free download AP CSP questions and answers, then click on the big idea:

  1. Creative Development
  2. Data
  3. Algorithms and Programming
  4. Computer Systems and Networks
  5. Impact of Computing

Multiples Choice Answers

  • data is sorted
  • code algorithm solution is d (see below)
  • computer-created font
d) if (small > num){
	small = num
}

Leave a Comment