Unit 3: Algorithms and Programming

AP Computer Science Principles: 50 practice questions with detailed explanations.

Unit Study Guide

Executive Summary

Programs store values, make decisions, repeat, and call reusable procedures. Algorithms differ in how much work they need as input grows.

Variables and expressions

Variables store values that change: x = x + 1 updates x. Expressions combine operators; the mod operator (%) gives remainders (17 mod 5 = 2). Strings concatenate with +; substrings extract parts.

Booleans and conditionals

Comparisons (==, >, <) give true/false; combine with AND (both), OR (either), NOT (flip). if/else runs one branch; nested ifs test layered conditions.

Iteration

Loops repeat while a condition holds. Count carefully: a counter starting at 0 with count < 5 runs five times. Use a loop with an index to modify lists; enhanced for only reads.

Lists and algorithms

Lists hold ordered values, indexed from 0. Linear search checks each element; binary search halves a SORTED list (about log2(n) checks). Efficiency measures how work grows with input size — binary search beats linear search on large inputs.

Procedures, randomness, and the limits of computing

Procedures group reusable code with parameters; libraries bundle prewritten procedures. Random values power simulations. Undecidable problems — like the halting problem — have NO algorithm that solves all cases.

Exam traps

Mod returns remainders, not quotients. Loops with ≤ run one too many times. Binary search needs sorted data. Efficiency is about growth, not speed of one run.

Top 5 Concepts to Master

  1. 1Trace variables, conditionals, and loops.
  2. 2Compare linear and binary search.
  3. 3Reason about algorithmic efficiency.
  4. 4Explain procedures, libraries, and simulations.

Key Terms & Definitions

Practice with Flashcards
Variable

Named storage for a changeable value.

Mod operator

% returns the remainder of division.

Conditional

if/else code running on a boolean test.

Iteration

Repeating code with loops.

List

Ordered collection indexed from 0.

Linear search

Checking elements one by one.

Binary search

Halving a sorted list each step.

Procedure

Named, reusable block of code.

Undecidable problem

No algorithm can solve it for all inputs.

Common Misconceptions: Exam Traps

Binary search works on any list.

Correct: The list must be sorted.

17 mod 5 is 3 because 5 goes in 3 times.

Correct: Mod returns the remainder: 2.

A faster computer changes an algorithm’s efficiency.

Correct: Efficiency is about how work grows, not hardware.

All problems can be solved by a clever enough program.

Correct: Undecidable problems have no algorithmic solution.

Question Bank Breakdown

By difficulty

easy 22medium 23hard 5

By topic

Binary Search 5Boolean Expressions 5Strings 5Mathematical Expressions 5Procedures 4Iteration 4Algorithmic Efficiency 3Developing Algorithms 3Lists 3Variables and Assignments 3Libraries 2Undecidable Problems 2Conditionals 2Simulations 1Random Values 1Nested Conditionals 1Data Abstraction 1

All Questions in this Unit