Pseudocode Variables, Assignment

The CSP Exam Reference Sheet defines a language-neutral pseudocode used across all programming questions: (1) Assignment.

What to practice

  • Trace sequential variable assignments, arithmetic expressions, and three-step variable swaps.
  • Execute 1-indexed list operations (aList[i], INSERT, APPEND, REMOVE, LENGTH) accurately.
  • Explain how list data abstraction simplifies programs by managing arbitrary-size collections under a single variable name.

1. Core Concept Instruction

The AP CSP Exam Reference Sheet defines a language-neutral pseudocode used across all programming questions: (1) Assignment uses a left arrow: x <- expression evaluates the right-hand side and stores the result in x, overwriting x's previous value. Swapping two variables x and y requires a third temporary variable: temp <- x; x <- y; y <- temp (writing x <- y; y <- x loses the original value of x!). (2) CRITICAL RULE: Lists in AP CSP pseudocode are 1-INDEXED! The first element is aList[1] and the last element is aList[LENGTH(aList)] (Accessing aList[0] or aList[LENGTH(aList) + 1] causes a runtime error). (3) List procedures: APPEND(aList, value) adds value to the end; INSERT(aList, i, value) inserts value at index i and shifts elements at i..end one position right; REMOVE(aList, i) deletes the element at index i and shifts elements at i+1..end one position left.

2. Worked Examples

Worked 1-Based AP CSP List Mutation Trace (INSERT, APPEND, REMOVE)

Trace the exact contents of scores after executing the following AP CSP pseudocode:
scores <- [10, 20, 30, 40]
INSERT(scores, 2, 15)
APPEND(scores, 50)
REMOVE(scores, 4)
scores[1] <- scores[2] + scores[3]

Result:

Variable Swap Trace & 1-Based List Traversal Accumulation

Trace the final values of x, y, and scores after executing:
x <- 12
y <- 25
temp <- x
x <- y
y <- temp
scores <- [10, 20, 30]
APPEND(scores, x + y)

Result: x = 25, y = 12, and scores = [10, 20, 30, 37] (with scores[4] = 37)

Core Concept Review

The AP CSP Exam Reference Sheet defines a language-neutral pseudocode used across all programming questions: (1) Assignment uses a left arrow: x <- expression evaluates the right-hand side and stores the result in x, overwriting x's previous value. Swapping two variables x and y requires a third temporary variable: temp <- x; x <- y; y <- temp (writing x <- y; y <- x loses the original value of x!). (2) CRITICAL RULE: Lists in AP CSP pseudocode are 1-INDEXED! The first element is aList[1] and the last element is aList[LENGTH(aList)] (Accessing aList[0] or aList[LENGTH(aList) + 1] causes a runtime error). (3) List procedures: APPEND(aList, value) adds value to the end; INSERT(aList, i, value) inserts value at index i and shifts elements at i..end one position right; REMOVE(aList, i) deletes the element at index i and shifts elements at i+1..end one position left.

Extended Concept Analysis

The AP CSP Exam Reference Sheet defines a language-neutral pseudocode used across all programming questions: (1) Assignment uses a left arrow: x <- expression evaluates the right-hand side and stores the result in x, overwriting x's previous value. Swapping two variables x and y requires a third temporary variable: temp <- x; x <- y; y <- temp (writing x <- y; y <- x loses the original value of x!). (2) CRITICAL RULE: Lists in AP CSP pseudocode are 1-INDEXED! The first element is aList[1] and the last element is aList[LENGTH(aList)] (Accessing aList[0] or aList[LENGTH(aList) + 1] causes a runtime error). (3) List procedures: APPEND(aList, value) adds value to the end; INSERT(aList, i, value) inserts value at index i and shifts elements at i..end one position right; REMOVE(aList, i) deletes the element at index i and shifts elements at i+1..end one position left.

Worked Problem Walkthrough

Worked 1-Based AP CSP List Mutation Trace (INSERT, APPEND, REMOVE)

Trace the exact contents of scores after executing the following AP CSP pseudocode: scores <- [10, 20, 30, 40] INSERT(scores, 2, 15) APPEND(scores, 50) REMOVE(scores, 4) scores[1] <- scores[2] + scores[3]

Variable Swap Trace & 1-Based List Traversal Accumulation

Trace the final values of x, y, and scores after executing: x <- 12 y <- 25 temp <- x x <- y y <- temp scores <- [10, 20, 30] APPEND(scores, x + y)

Common Exam Traps & How to Avoid Them

  • Treating AP CSP lists as 0-indexed like Java/Python instead of 1-indexed as specified on the AP CSP Exam Reference Sheet.

  • Writing a <- b followed by b <- a to swap two variables without a temp variable, which sets both variables to b's initial value.

Key Vocabulary

  • 1-Based Indexing: The AP CSP pseudocode convention where the first element of a list L is accessed at index 1 (L[1]) and the last at L[LENGTH(L)].

  • Data Abstraction: Managing complexity by grouping related data items into a single named collection (like a list) without referencing each element by a separate variable name.

Use this chapter companion

Review the lesson, attempt the original practice, then check the explanation. Your printed study guide remains complete without the website.

Independence

Skill by Skill Prep is independent. SAT® and AP® are trademarks registered by the College Board, which is not affiliated with, and does not endorse, this website or book. PSAT/NMSQT® is a registered trademark of the College Board and the National Merit Scholarship Corporation, which are not affiliated with, and do not endorse, this site. Bluebook™ is a trademark of the College Board. ACT® is a trademark of ACT Education Corp., which is not affiliated with and does not endorse this website or book. Desmos is a trademark of Desmos Studio PBC. Practice results describe these questions, not official scores or admission predictions.

Last updated .