AP Computer Science Principles, Unit 3
Exam words: Algorithms and Programming
The 71 words a written answer in this unit needs. For each one: what it means, a wording that loses the mark and why, and a sentence that uses it the way a full answer would.
Study these words as a deck
Flashcards, Learn, Test and Match in Cards, with your Still learning marks kept, and the booklet to print on A4 or US Letter. Sign in to open it.
The words
variable
A named place in a program that holds one value at a time.
Loses the mark: “the variable keeps every value it was given”. Setting a variable replaces its old value, so it holds only the latest one.
Example: In the Brightwood quiz app, the variable `score` holds 4 after `score ← score + 1` runs on a score of 3.
assignment
Setting a variable to a value with ←, replacing whatever it held before.
Loses the mark: “after b ← a, b and a are the same variable”. Assignment copies the value at that moment; changing a later does not change b.
Example: The assignment `total ← total + price` in the Clearbrook checkout program adds the item's price to the running total.
data type
The kind of a value, such as a number, a string or a Boolean.
Loses the mark: “a value in quotes such as "12" is a number”. Quotes make it a string, so "12" joins with other text instead of adding to numbers.
Example: In the Rockport survey program, `age` holds a value of the number data type while `name` holds a string.
list
An ordered collection of values stored under one name, each reached by its index.
Loses the mark: “a list only saves typing”. A list lets one piece of code handle any number of values, so the program still works when more data arrives.
Example: The Redwood swim team program keeps all eight lap times in one list, `times`, so `times[3]` is the third swimmer's time.
element
One value stored in a list, at a particular position.
Loses the mark: “setting nums[2] inserts a new element at position 2”. Setting an element replaces the value at that position; the list stays the same length.
Example: In `colors ← ["red", "blue", "gold"]` from the Easton flag program, the element at index 2 is "blue".
index
A whole number giving an element's position in a list; here lists count from 1.
Loses the mark: “nums[3] means the value 3”. The index is a position: `nums[3]` is whatever value sits third in the list.
Example: In the Hollis bus program, `stops[LENGTH (stops)]` uses the list's length as the index of its last stop.
data abstraction
Giving a collection of data one name, so code can use it without its details.
Loses the mark: “putting the values in one list loses track of which is which”. Each element keeps its position, so the list holds the same information as separate variables, under one name.
Example: Using data abstraction, the Aldergrove pantry app stores every donation in one list, `donations`, so a new donor needs no new variable.
abstraction
Hiding details behind a name so something can be used without knowing how it works.
Loses the mark: “abstraction means making the code shorter”. Abstraction hides details behind a name; the gain is code that is simpler to use and to change, not fewer lines.
Example: The Larchmont store's checkout calls `shippingCost (weight)` without knowing the rate table inside it, an example of procedural abstraction.
expression
A combination of values, variables and operators that a program evaluates to one value.
Loses the mark: “total ← a + b makes total update whenever a changes”. The expression is evaluated once, when the line runs; total keeps that value until it is set again.
Example: In the Granite Falls fare program, the expression `2 + 3 * 4` evaluates to 14, because multiplication comes first.
arithmetic operator
A symbol for a math operation: `+`, `-`, `*`, `/` or `MOD`.
Loses the mark: “7 / 2 in code is 3 because the decimal is cut off”. In this course's code `/` divides exactly, so 7 / 2 is 3.5.
Example: The Maple Grove recipe program uses the arithmetic operator `*` to double each amount: `cups ← cups * 2`.
MOD
The operator giving the remainder after division: `17 MOD 5` is 2.
Loses the mark: “17 MOD 5 is 3 because 5 goes into 17 three times”. That counts how many times 5 fits; MOD gives what is left over, which is 2.
Example: The Pinecrest calendar program tests `day MOD 7 = 0` to find every seventh day.
order of operations
The rule that `*`, `/` and `MOD` come before `+` and `-`, with parentheses first.
Loses the mark: “expressions are worked strictly left to right”. Multiplication, division and MOD go first, so 2 + 3 * 4 is 14, not 20.
Example: By the order of operations, `(4 + 6) / 2 * 3` is 15 in the Westlake grading program: the parentheses first, then `/` and `*` from left to right.
sequencing
Running statements one after another in the order they are written.
Loses the mark: “the program happens all at once so every line sees the final values”. Each line runs in turn and sees only the values set by the lines before it.
Example: With `lives` at 10, sequencing decides what the Ferndale game shows: 10 if `DISPLAY (lives)` comes before `lives ← lives - 1`, and 9 if it comes after.
operand
A value an operator acts on, such as 3 and `x` in `3 + x`.
Loses the mark: “the operand is the plus or minus sign”. The sign is the operator; the operands are the values it combines.
Example: In `price * 0.9` from the Hartwell discount program, the operands are `price` and 0.9, and `*` is the operator.
string
A sequence of characters, such as letters, digits and spaces, treated as text.
Loses the mark: “"12" and "30" are numbers so joining them gives 42”. In quotes they are strings, so joining them gives "1230"; they are not added.
Example: The Eastport badge program stores each code as a string, so "0042" keeps its leading zeros.
string concatenation
Joining two strings end to end into one string, adding nothing between them.
Loses the mark: “concat puts a space between the two words”. Concatenation adds nothing between the strings, so `concat ("sun", "flower")` gives "sunflower".
Example: The Cobalt Bay greeting uses string concatenation: `concat ("Hi, ", name)` gives "Hi, Rosa" when `name` is "Rosa".
substring
Part of a string: a set number of characters from a start position.
Loses the mark: “substring (word, 5, 8) means letters 5 to 8”. The third value is how many characters to take, so it gives 8 characters starting at position 5.
Example: In the Silverton ID program, `substring ("PX-2041", 4, 4)` is the substring "2041".
character
One letter, digit, space or symbol in a string.
Loses the mark: “spaces do not count as characters”. A space is a character like any other, so "go team" holds 7 characters.
Example: `charCount ("Bay 9")` is 5 in the Crestwood locker program, because the space is a character too.
string length
The number of characters in a string, spaces and symbols included.
Loses the mark: “the string length is the number of words”. Length counts characters, not words, so "go team go" has length 10.
Example: The Fairhaven sign-up form checks that `charCount (code)` is 6, so every code has a string length of exactly 6.
Boolean value
One of the two values true and false.
Loses the mark: “a comparison cannot be stored in a variable”. A comparison evaluates to true or false, which can be stored, as in `passed ← (score ≥ 50)`.
Example: In the Linwood alarm program, `doorOpen` holds a Boolean value, true while the door is open.
Boolean expression
An expression that evaluates to true or false, such as `score ≥ 50`.
Loses the mark: “temp = 75 sets temp to 75”. `=` compares and gives true or false; only ← changes a variable.
Example: The Boolean expression `(age ≥ 13) AND (age ≤ 18)` is true for a 15-year-old using the Brookhaven teen center app.
relational operator
A comparison operator, `=`, `≠`, `<`, `≤`, `>` or `≥`, that gives true or false.
Loses the mark: “at least 50 and more than 50 mean the same thing”. `score > 50` is false for 50 and `score ≥ 50` is true, so the two differ exactly at the cutoff.
Example: The Highmoor library program uses the relational operator `≥` in `fines ≥ 10`, so a fine of exactly 10 blocks borrowing.
logical operator
`AND`, `OR` or `NOT`, which combine or reverse Boolean values.
Loses the mark: “the rule says under 0 and over 30 so the code uses AND”. No temperature is both, so `(t < 0) AND (t > 30)` is never true; the rule needs OR.
Example: The Ashby greenhouse warns when `(t < 5) OR (t > 35)`, using the logical operator OR so either extreme sets off the alarm.
AND
A logical operator that is true only when both conditions are true.
Loses the mark: “AND is true if either side is true”. That describes OR; AND needs both sides to be true.
Example: The Glenrock gate opens on `(hasTicket = true) AND (age ≥ 12)`, so AND keeps out a ticket holder who is 10.
OR
A logical operator that is true when at least one condition is true.
Loses the mark: “true OR true is false because OR means pick one”. OR is true when either or both sides are true, so true OR true is true.
Example: The Oakdale museum gives free entry when `(age < 5) OR (age ≥ 65)`, so OR makes both a 3-year-old and a 70-year-old free.
NOT
A logical operator that turns true into false and false into true.
Loses the mark: “NOT (a AND b) is the same as NOT a AND NOT b”. NOT of an AND becomes an OR of the NOTs: NOT (a AND b) equals (NOT a) OR (NOT b).
Example: `NOT (isClosed)` is true when the Riverbend pool is open, because NOT reverses the Boolean value.
truth table
A table listing a Boolean expression's value for every combination of true and false inputs.
Loses the mark: “a truth table only needs the rows where the answer is true”. Every combination of inputs gets a row, so a table for two conditions has four rows.
Example: A truth table for `a OR b` has four rows, and only the row where both are false gives false.
conditional statement
An IF statement: code that runs a block only when its condition is true.
Loses the mark: “the ELSE block runs as well when the IF condition is true”. Exactly one of the two blocks runs: the IF block when the condition is true, the ELSE block only when it is false.
Example: The Westfield parking program's conditional statement `IF (hours > 2)` adds a fee only for cars parked longer than two hours.
selection
Choosing which part of an algorithm runs, based on a condition.
Loses the mark: “the program picks whichever branch best fits the answer”. Selection follows the conditions in the code in order, even when a later branch would fit better.
Example: Selection in the Northfield shipping program sends orders over 5 pounds down one path and lighter orders down another.
nested conditional
An IF statement inside the block of another IF or ELSE.
Loses the mark: “an inner IF is checked whatever happens outside it”. The inner IF runs only when the outer block runs, so otherwise its condition is never checked.
Example: In the Brightmoor grading program, a nested conditional checks `score ≥ 90` only inside the ELSE of `IF (score < 60)`, so a score of 50 never reaches it.
branch
One of the blocks a conditional statement can run, chosen by its condition.
Loses the mark: “code after the IF ELSE belongs to the ELSE branch”. Lines after the whole IF ELSE run whichever branch was taken.
Example: When `balance` is 30, the Kingsley bank app takes the ELSE branch of `IF (balance ≥ 50)` and shows a low-balance warning.
iteration
Repeating a block of code a set number of times or until a condition holds.
Loses the mark: “each pass starts again from the original values”. Variables keep the values the last pass gave them, so a running total grows pass by pass.
Example: Iteration lets the Clayton rain gauge program add up 30 daily readings with one loop instead of 30 separate lines.
count-controlled loop
A loop that repeats a set number of times, such as `REPEAT 5 TIMES`.
Loses the mark: “REPEAT 4 TIMES runs five times because counting starts at 0”. `REPEAT 4 TIMES` runs its block exactly 4 times; there is no counter starting at 0.
Example: The Dunmore drill program uses a count-controlled loop, `REPEAT 3 TIMES`, so the warning beep sounds exactly three times.
condition-controlled loop
A loop whose condition, checked before each pass, decides whether it repeats again.
Loses the mark: “REPEAT UNTIL runs its block once before checking”. The condition is checked before each pass, so if it is already true the block runs zero times.
Example: The Pell Lake pump program's condition-controlled loop, `REPEAT UNTIL (level ≤ 10)`, never runs if the tank already holds 8.
infinite loop
A loop whose stopping condition never becomes true, so it repeats forever.
Loses the mark: “the loop stops once the counter passes the stopping value”. `REPEAT UNTIL (n = 0)` checks for exactly 0, so n going 3, 1, -1 skips it and never stops.
Example: Counting down by 2 from 7, the Ridgefield timer's `REPEAT UNTIL (t = 0)` is an infinite loop, since t goes 7, 5, 3, 1, -1 and never equals 0.
algorithm
A finite set of clear steps that solves a problem or completes a task.
Loses the mark: “each problem has only one correct algorithm”. Different algorithms, such as counting up or counting down, can solve the same problem correctly.
Example: The Westmoor club's algorithm for the highest score sets `best` to the first score, then compares each later score with `best`.
pseudocode
Plain, structured steps that describe an algorithm without a real language's exact rules.
Loses the mark: “pseudocode can be run on a computer as it is”. Pseudocode is for people to read and plan with; it must be turned into a real language to run.
Example: Before coding, the Elmhurst team wrote pseudocode: for each order, if it is late, add it to the late list.
flowchart
A diagram of an algorithm's steps, with arrows for order and diamonds for decisions.
Loses the mark: “a flowchart shows only the steps, not the decisions”. Each decision in a flowchart is a diamond with one arrow per answer, so the branches are drawn too.
Example: The Cliffside library's flowchart for renewals has a diamond asking whether the book is on hold, with a yes arrow and a no arrow.
traversal
Visiting each element of a list or other collection in turn, usually with a loop.
Loses the mark: “in FOR EACH x IN scores, x is the position”. x holds each element's value in turn, not its index.
Example: A traversal of the Bramble Hill sign-up list with `FOR EACH name IN signups` checks each name in turn.
append
Adding an element to the end of a list, making it one longer.
Loses the mark: “APPEND puts the new element at the front”. APPEND always adds at the end; INSERT is how an element goes anywhere else.
Example: `APPEND (queue, "Rafa")` in the Dovecote barber app makes the queue one longer, with Rafa last.
insert
Putting an element at a given position and moving later elements one place along.
Loses the mark: “INSERT replaces the element at that position”. INSERT adds an element and moves the rest along, so nothing is lost and the list grows by one.
Example: `INSERT (stops, 2, "Fir")` turns the Greenway route `["Ash", "Oak", "Elm"]` into `["Ash", "Fir", "Oak", "Elm"]`.
remove
Taking out the element at a given position and closing the gap behind it.
Loses the mark: “REMOVE (seats, 2) takes the value 2 out of the list”. The 2 is a position: REMOVE takes out whatever element is second.
Example: After `REMOVE (seats, 1)`, the Lantern theater program's second seat becomes the first, because remove closes the gap.
list length
The number of elements a list holds, given by `LENGTH (list)`.
Loses the mark: “the last element is at index LENGTH minus 1”. Lists here count from 1, so the last element is at index `LENGTH (list)` itself.
Example: The Eastbrook roster program uses `LENGTH (players)` as the list length, so its loop still works when a ninth player joins.
index out of range
An error from using an index below 1 or past the end of a list.
Loses the mark: “an index past the end just gives the last element”. There is no element there, so the program stops with an error instead of guessing.
Example: Reading `temps[8]` from the Oriel weather program's list of 7 readings is an index out of range, and the program stops.
linear search
Checking a list's elements one at a time, in order, until the target is found.
Loses the mark: “a search always has to check every element”. A linear search stops at the first match, and a binary search skips most elements.
Example: A linear search of the unsorted Hawthorn lost-and-found list may check all 300 items before finding the one umbrella.
binary search
Searching a sorted list by checking the middle, then discarding the half without the target.
Loses the mark: “binary search checks every item”. Each check halves what is left, so about 10 checks cover 1,000 sorted items.
Example: A binary search of the Marlow phone book's 1,000 sorted names needs at most 10 checks, since .
sorted list
A list whose elements are in order, such as smallest to largest.
Loses the mark: “binary search is always the quicker choice”. For an unsorted list, sorting it first can cost more than one linear search.
Example: Because the Sedgewick ticket numbers are a sorted list, the app can use binary search instead of checking each one.
search algorithm
An algorithm that finds where, or whether, a value appears in a collection.
Loses the mark: “a search loop stops on its own when it finds a match”. Unless the code stops it, the loop keeps going after a match and can overwrite the position it found.
Example: The Quillan pet shelter's search algorithm returns the position of a microchip number, or 0 if no animal has it.
procedure
A named block of code that runs when called, possibly with parameters.
Loses the mark: “a procedure's code runs where it is written in the program”. A procedure's block runs only when it is called, however early it is written.
Example: The Ellery bakery program defines the procedure `boxCount (muffins)` once and calls it for every order.
parameter
A name in a procedure's definition that receives a value each time it is called.
Loses the mark: “changing a parameter changes the variable that was passed in”. A parameter holds a copy of the value, so the caller's variable keeps its own value.
Example: In `PROCEDURE tip (bill, percent)` from the Carver cafe app, `bill` and `percent` are parameters.
argument
A value passed to a procedure in a call, matched to its parameters by position.
Loses the mark: “arguments go to the parameters with the same names”. Arguments are matched by order, first to first, whatever their names.
Example: In the Carver cafe app's call `tip (40, 15)`, the arguments 40 and 15 go to `bill` and `percent` in that order.
return value
The value a procedure sends back to where it was called, using RETURN.
Loses the mark: “RETURN displays the value”. RETURN hands the value back to the call; nothing shows unless the caller displays it.
Example: With six muffins to a box, `boxCount (14)` has the return value 3, which the Ellery bakery program stores with `boxes ← boxCount (14)`.
procedure call
Running a procedure by writing its name with arguments, such as `average (6, 9)`.
Loses the mark: “after the call the program starts again from the top”. When the procedure finishes, the program carries on from just after the call.
Example: Each procedure call `price (size)` in the Tamsin pizza app runs the same code with a different size.
modularity
Splitting a program into separate procedures, each doing one job.
Loses the mark: “using a procedure means knowing how its code works”. A caller needs only the procedure's name, parameters and result, so its inside can change without the callers changing.
Example: Thanks to modularity, the Brennan fare app keeps its discount rules in one procedure, so a rule change touches only that procedure.
library
A collection of ready-made procedures a program can use without writing them.
Loses the mark: “you must read a library's code to use it”. A library procedure's description, its name, parameters and result, is enough to call it.
Example: The Hartley chess club app uses a date library's `daysBetween (start, end)` instead of writing its own calendar math.
application programming interface
A description of how to use a library or service: its procedures, inputs and outputs.
Loses the mark: “an API is the library's code”. An API describes what each procedure takes and returns; the code behind it can stay hidden.
Example: The Larkhill weather API says `forecast (zip, days)` returns a list of daily highs, which is all the app's builders needed to know.
module
A separate file or unit of code whose procedures other programs can use.
Loses the mark: “calling a library procedure on a list changes the list”. Unless its description says it changes the list, a procedure works from the values it is given and returns a result.
Example: The Penrose team put its scoring procedures in one module, so both the phone app and the website use the same code.
random number generator
A procedure that produces unpredictable numbers, such as `RANDOM (1, 6)` for a die.
Loses the mark: “RANDOM (1, 6) never gives 6”. Both ends are included, so 1 through 6 are each equally likely.
Example: The Kettle Cove board game calls the random number generator `RANDOM (1, 6)` each turn to move a piece 1 to 6 squares.
simulation
A program that models a real process, often with random values, to study its outcomes.
Loses the mark: “a correct simulation gives the same result every run”. Random values make each run differ; the spread of many runs is the result.
Example: The Ostrander clinic ran a simulation of 1,000 random mornings to estimate how long patients would wait with one more nurse.
pseudorandom number
A number from a formula that only appears random, repeating if started the same way.
Loses the mark: “a value becomes less likely after it has just come up”. Each value is equally likely on every call; past results do not change the next one.
Example: The Brindle card game shuffles with pseudorandom numbers, so a saved starting value lets testers replay the same shuffle.
Monte Carlo method
Estimating an answer by running many random trials and summarizing the results.
Loses the mark: “one run of a random simulation is enough”. Single runs vary; many trials are needed before their average settles.
Example: Using the Monte Carlo method, the Halstead team ran 10,000 simulated seasons to estimate the chance of a winning record.
efficiency
How an algorithm's number of steps grows as its input gets larger.
Loses the mark: “twice the data means twice the time for every algorithm”. Growth depends on the algorithm: binary search adds one step, while a loop inside a loop takes four times as many.
Example: The efficiency of the Corbin league's pairing program matters: comparing every team with every other takes about steps, so 100 teams need 10,000.
reasonable time
Running time that grows no faster than a polynomial, such as or steps.
Loses the mark: “any algorithm whose steps grow fast is unreasonable”. grows quickly but is still polynomial, so it runs in reasonable time.
Example: Checking every pair of 500 Delmar bus stops takes about 250,000 steps, which is reasonable time because it grows as .
unreasonable time
Running time that grows exponentially or faster, such as steps.
Loses the mark: “an unreasonable algorithm never gives an answer”. It gives a correct answer for small inputs; only larger inputs take impractically long.
Example: Trying every route through 25 Westbury delivery stops takes unreasonable time, because the number of routes grows faster than .
heuristic
A shortcut rule that quickly finds a good, not always best, answer.
Loses the mark: “a heuristic always finds the best answer, just faster”. A heuristic trades the guarantee of the best answer for speed; its answer is usually close, not always best.
Example: The Glenhaven delivery app uses a heuristic, always driving to the nearest unvisited stop, which plans routes in seconds but not always the shortest.
brute force
Solving a problem by trying every possible answer and checking each one.
Loses the mark: “trying every possibility is too slow to ever use”. For small inputs brute force is often the simplest correct choice; it fails only as inputs grow.
Example: Brute force scheduling for the Harrow chess club tries every order of 6 matches, all 720 of them, and keeps the best.
optimization problem
A problem asking for the best answer among many, such as the shortest route.
Loses the mark: “every optimization problem can be solved exactly in reasonable time”. For many, such as the shortest tour of many cities, no reasonable-time algorithm is known, so heuristics are used.
Example: Finding the cheapest way to visit all 12 Rowan County libraries is an optimization problem, since many routes work but only one is cheapest.
decision problem
A problem with a yes or no answer for each input.
Loses the mark: “a decision problem asks for the best answer”. A decision problem asks only yes or no; finding the best answer is an optimization problem.
Example: "Is this number prime?" is a decision problem: the Ventry math app answers yes or no for each number.
undecidable problem
A decision problem no algorithm can answer correctly for every possible input.
Loses the mark: “undecidable means nobody has found the algorithm yet”. It is proved that no such algorithm can exist, so no future discovery will produce one.
Example: Because checking whether any program stops is an undecidable problem, the Dunmore code checker can warn about some loops but cannot judge every program.
decidable problem
A decision problem some algorithm answers correctly for every input.
Loses the mark: “more computing power could decide any problem”. Undecidability is about whether an algorithm exists, so faster machines or smarter software do not change it.
Example: Whether a list contains a negative number is a decidable problem: a loop over the list answers it for every list.
halting problem
Deciding, for any program and input, whether the program eventually stops; it is undecidable.
Loses the mark: “run the program and wait to see whether it stops”. A program still running after an hour may stop after two, so waiting can never settle it.
Example: The halting problem means no tool, including the Fenwick class's grader, can decide for every submitted program whether it will finish.