AP CSP Unit 6: Algorithms, Efficiency, and Simulations
27 multiple-choice questions on AP Computer Science Principles Unit 6, Algorithms, Efficiency, and Simulations, organized by topic. They are not tied to any one class or teacher: they follow the College Board course framework. Learn the 7 key terms with the flashcards first, then test yourself. Every answer comes with a short explanation.
Take the practice test · Flashcards · All study tools
What it covers
- 6.1 Developing algorithms
- 6.2 Searching and efficiency
- 6.3 Simulations
Key terms
6.3 Simulations
- Algorithm
- A finite set of instructions that accomplishes a task
- Linear search
- Checking each element in order
- Binary search
- Repeatedly checking the middle of a sorted list and discarding half
- Reasonable time
- Algorithms whose steps grow polynomially with input size
- Heuristic
- An approach that finds an approximate solution when an exact one is impractical
- Undecidable problem
- A problem for which no algorithm always gives a correct yes-or-no answer
- Simulation
- A model of a real-world process using abstractions
Sample practice questions
An algorithm is
- any computer program, as long as it is written in Java
- a type of computer hardware that carries out instructions
- a random sequence of steps that may or may not finish
- a finite set of instructions that accomplishes a specific task
Answer: D. a finite set of instructions that accomplishes a specific task Algorithms can be expressed in natural language, diagrams, pseudocode or code.
Linear search on a list of 1,000 unsorted names checks, in the worst case,
- 10 names
- 500 names
- 1 name
- 1,000 names
Answer: D. 1,000 names Without order, each element may need to be checked.
A simulation is
- an exact copy of reality that includes every detail
- always less useful than a real-world experiment
- a program that models a real-world process using abstractions
- a type of compression used for large data sets
Answer: C. a program that models a real-world process using abstractions Simulations represent real events, removing details that are less important.
Every algorithm can be constructed using
- only loops, with no IF statements
- only IF statements, with no loops
- recursion only, with no sequencing
- sequencing, selection and iteration
Answer: D. sequencing, selection and iteration These three building blocks are enough to express any algorithm.
Binary search can be used only when
- the list has fewer than 100 elements
- the list contains numbers only
- the list is sorted
- the list is unsorted
Answer: C. the list is sorted Binary search compares with the middle element to discard half, which requires order.
An advantage of a simulation over a real-world experiment is that it
- always gives exact results that match the real world in every detail
- never contains bias, since the computer makes all of the decisions
- doesn't need any assumptions, since it uses real data from the world
- can be faster, cheaper and safer, and test conditions that are hard to create
Answer: D. can be faster, cheaper and safer, and test conditions that are hard to create For example, simulating a hurricane is safer than waiting for one.
Selection in an algorithm refers to
- running each step in order, one after another
- repeating steps until a condition is met
- choosing which steps to run based on a condition
- picking an item from a list at random
Answer: C. choosing which steps to run based on a condition IF statements implement selection.
About how many steps does binary search need in the worst case for a sorted list of 1,000,000 items?
- 1,000,000
- 20
- 500,000
- 1,000
Answer: B. 20 Each step halves the list; 2²⁰ ≈ 1,000,000.
A limitation of simulations is that
- they can't use random numbers, so they can't model chance events
- they rely on simplifying assumptions, so results may not match reality
- they can't be repeated, since each run changes the program's code
- they are always more expensive to run than real-world experiments
Answer: B. they rely on simplifying assumptions, so results may not match reality Simplifications and possible bias in the model affect results.
Two different algorithms that solve the same problem
- must produce different results for at least some inputs
- must be written in different programming languages
- can both be correct while differing in efficiency or clarity
- can't both be correct, since only one can be most efficient
Answer: C. can both be correct while differing in efficiency or clarity Many algorithms can solve a problem; some are faster or easier to understand.
More AP Computer Science Principles
- Unit 1: Creative Development
- Unit 2: Binary and Data Representation
- Unit 3: Data Compression and Using Data
- Unit 4: Variables, Expressions, and Lists
- Unit 5: Iteration, Procedures, and Libraries
- Unit 7: The Internet and Computer Systems
- Unit 8: Impact of Computing
- Unit 9: Legal, Ethical, and Safe Computing
Studying for a test in your own class? Make a practice test from your class notes.