AP CSP Filtering Sorting Practice

10 Questions Big Idea 3 3 Question Types Predict First

AP CSP Filtering, Sorting & Boolean Expressions

Big Idea 3: Algorithms & Programming — Boolean Logic, Filter/Sort Ordering & Algorithm Step Sequencing

Exam Tip: These three question types appear on virtually every AP CSP exam. Keywords in the question stem are your signals — highlighted in yellow throughout this practice set. For ordering questions, always trace the sequence on the table before picking an answer. For boolean questions, ask: “can a single row ever satisfy both conditions simultaneously?”
Your Score 0 / 10

Section 1: Boolean Expressions

Each question shows a spreadsheet. Write the correct AND/OR filter condition.

Before revealing choices: (1) Underline the keywords — at least, or less, AND/OR. (2) Check each condition: does it filter a single value or one of several values? If one of several, you need OR inside. (3) Ask: could a single row ever satisfy both inner conditions at the same time? If not, AND is wrong.
✎ Quick Rule: AND vs. OR for Multi-Value Fields
✗ Wrong — Impossible Condition
(day = "Friday") AND (day = "Saturday")
A single day field holds one value. It can never equal two different strings simultaneously. This expression is always false — nothing is ever counted.
✓ Correct — Either Value Allowed
(day = "Friday") OR (day = "Saturday")
OR allows the field to match either value. A show on Friday evaluates the left side as true; a show on Saturday evaluates the right side as true. Both are counted.

Rule: When the question says “A or B,” “either A or B,” or lists multiple allowed values for one field → use OR between those values. Use AND only when separate conditions must all be true at once.

1
Write the Boolean Expression
MediumBoolean Filtering
Event Name Type Cost ($) Seats Available
Spring Workshop workshop 20 5
History Lecture lecture 20 5
Art Workshop workshop 30 5
Coding Workshop workshop 25 0
Design Workshop workshop 25 3

▮ Green rows = expected matches for this goal

Variables: evType = event type (string)  •  cost = cost in dollars (number)  •  seats = seats available (number)

A student wants to count events that meet all three of the following criteria: the event is a workshop, the cost is $25 or less, and at least one seat is available. Which expression evaluates to true for events that should be counted?

2
AND vs. OR — The Day-of-Week Trap
HardBoolean Filtering
Watch for: Ask yourself: can a single show be on Friday and Saturday at the same time?
Show Name Genre Day Start Time
Late Night Jazz jazz Friday 9:00 PM
Weekend Groove jazz Saturday 7:00 PM
Blues Hour blues Friday 8:00 PM
Sunday Sessions jazz Sunday 6:00 PM
Jazz Brunch jazz Saturday 11:00 AM

▮ Green rows = expected matches for this goal

Variables: genre = genre (string)  •  day = day of week (string)

A student wants to count shows that are a jazz show AND take place on Friday OR Saturday. Which expression evaluates to true for shows that should be counted?

3
Boundary Value — < vs. ≤
HardBoolean Filtering
Watch for: “At least 4.0” includes 4.0 itself. Which operator includes the boundary?
Product Category Rating In Stock
Wireless Speaker electronics 4.5 true
Desk Lamp electronics 3.5 true
Yoga Mat fitness 4.5 true
USB Hub electronics 4.0 false
Phone Stand electronics 4.0 true

▮ Green rows = expected matches for this goal

Variables: cat = category (string)  •  rating = average rating (number)  •  inStock = availability (boolean)

A student wants to count electronics products that have a rating of at least 4.0 and are currently in stock. Which expression evaluates to true for products that should be counted?

4
Multi-Value Field — The Impossible AND
HardBoolean Filtering
Watch for: A customer has exactly ONE membership value. Can it ever equal both “gold” AND “platinum” at the same time?
Customer ID Status Membership Orders
C001 active gold 8
C002 active platinum 12
C003 inactive gold 3
C004 active silver 6
C005 active gold 5

▮ Green rows = expected matches for this goal

Variables: status = account status (string)  •  membership = membership tier (string)

A student wants to count customers who are active and have either a gold or platinum membership. Which expression evaluates to true for customers that should be counted?

Section 2: Filter & Sort Ordering

Which sequence of filter and sort steps puts the target row at position 1?

Before revealing choices: Trace each sequence on the table above. Ask two questions: (1) Does the sequence use the correct sort key (e.g., sort by age to find youngest — not by name)? (2) After all steps complete, which row is first? The green rows in the table show the expected matches.
5
Which Sequences Find the Right Row?
HardFilter / Sort Ordering

Goal: find the youngest Marketing employee. Unknown ages are stored as 0 and should be ignored. The target employee must appear in row 1 when complete.

Name Dept Age Notes
Chen, M. Marketing 28
Davis, T. Marketing 0 unknown age
Adams, R. Sales 24
Brown, K. Marketing 35
Foster, L. Marketing 42

▮ Green rows = expected matches for this goal

Available Actions
Filter by departmentRemove entries where dept ≠ Marketing
Filter unknown ageRemove entries where age = 0
Sort by ageSort from least to greatest age
Sort by nameSort alphabetically by last name
Trace Each Sequence First
Seq I
Filter dept
Filter age=0
Sort age ASC
Row 1 = Chen (28) ✓
Seq II
Filter age=0
Sort age ASC
Filter dept
Row 1 = Chen (28) ✓
Seq III
Filter dept
Sort name A-Z
Filter age=0
Row 1 = Brown (35) ✗
Seq IV
Sort age ASC
Filter dept
Filter age=0
Row 1 = Chen (28) ✓
Note: Applying a filter does not change the relative order of remaining rows.
I. Filter by department → Filter unknown age → Sort by age
II. Filter unknown age → Sort by age → Filter by department
III. Filter by department → Sort by name → Filter unknown age
IV. Sort by age → Filter by department → Filter unknown age

Which of the sequences correctly places the youngest Marketing employee in row 1?

6
Select Two — Which Orderings Work?
HardFilter / Sort Ordering — Select Two
Watch for: Which sort direction puts the most expensive item at row 1?

Goal: find the most expensive available furniture item with a listed price. Items with no price are stored as -1 and should be ignored. The target must appear in row 1.

Product Category Price ($) Available
Bookshelf furniture 499 true
Side Table furniture -1 true
Laptop electronics 999 true
Coffee Table furniture 299 true
Wardrobe furniture 599 false

▮ Green rows = expected matches for this goal

Available Actions
Filter by categoryRemove entries where category ≠ furniture
Filter unknown priceRemove entries where price = -1
Filter availableRemove entries where available = false
Sort price descendingSort greatest to least price
Sort price ascendingSort least to greatest price
Trace Each Sequence First
Seq A
Filter cat
Filter avail
Filter price=-1
Sort DESC
Row 1 = Bookshelf $499 ✓
Seq B
Filter price=-1
Filter avail
Sort DESC
Filter cat
Row 1 = Bookshelf $499 ✓
Seq C
Sort DESC
Filter cat
Filter avail
Filter price=-1
Row 1 = Bookshelf $499 ✓
Seq D
Filter cat
Filter price=-1
Sort ASC
Filter avail
Row 1 = Coffee Table $299 ✗
Note: Applying a filter does not change the relative order of remaining rows.
A. Filter category → Filter available → Filter unknown price → Sort price descending
B. Filter unknown price → Filter available → Sort price descending → Filter category
C. Sort price descending → Filter category → Filter available → Filter unknown price
D. Filter category → Filter unknown price → Sort price ascending → Filter available

Select two sequences that correctly place the most expensive available furniture item with a listed price in row 1.

ⓘ Select TWO answers.
7
I, II, III — Which Orderings Work?
HardFilter / Sort Ordering — I & II Format
Watch for: Two sequences use the correct sort key. One uses the wrong sort key entirely.

Goal: find the oldest sci-fi novel with a known author and year. Unknown values are stored as “(unknown)” or -1. The target must appear in row 1.

Title Author Year Genre
Dune Herbert 1965 sci-fi
Unknown Novel (unknown) 1998 mystery
Foundation Asimov 1951 sci-fi
Neuromancer Gibson -1 sci-fi
Ender's Game Card 1985 sci-fi

▮ Green rows = expected matches for this goal

Available Actions
Filter by genreRemove entries where genre ≠ sci-fi
Filter unknown authorRemove entries where author = “(unknown)”
Filter unknown yearRemove entries where year = -1
Sort by year ascendingSort oldest (smallest year) to newest
Sort by title A-ZSort alphabetically by title
Trace Each Sequence First
Seq I
Filter genre
Filter unknown author
Filter year=-1
Sort year ASC
Row 1 = Foundation 1951 ✓
Seq II
Filter year=-1
Filter genre
Sort year ASC
Filter unknown author
Row 1 = Foundation 1951 ✓
Seq III
Filter genre
Sort title A-Z
Filter unknown author
Filter year=-1
Row 1 = Dune 1965 ✗
Note: Applying a filter does not change the relative order of remaining rows.
I. Filter genre → Filter unknown author → Filter unknown year → Sort year ascending
II. Filter unknown year → Filter genre → Sort year ascending → Filter unknown author
III. Filter genre → Sort title A-Z → Filter unknown author → Filter unknown year

Which sequences correctly place the oldest sci-fi novel with a known author and year in row 1?

Section 3: Algorithm Step Ordering

Some steps depend on the output of other steps — they can’t run first.

Before revealing choices: Draw the dependency chain. Ask for each step: “What data does this step need as input? Has that data been created yet?” A step cannot run before the step that produces its required input.
8
Which Step Order Produces the Correct Result?
MediumAlgorithm Step Ordering
Watch for: Which step must run first before any of the others make sense?

A programmer wants an algorithm that takes a list of email addresses and returns a sorted list of unique domain names (the part after the @).
Example: [“[email protected]”, “[email protected]”, “[email protected]”] → [“google.com”, “yahoo.com”].

Algorithm Steps
Extract: Extract the domain from each email (everything after the @)
Remove duplicates: Remove duplicate domain names from the list
Sort: Sort the domain names alphabetically
I. Extract → Remove duplicates → Sort
II. Extract → Sort → Remove duplicates
III. Remove duplicates → Extract → Sort
IV. Sort → Extract → Remove duplicates

Executing which of the following sequences will produce the correct sorted list of unique domain names?

9
Step Dependencies — What Needs What?
HardAlgorithm Step Ordering
Watch for: Draw the dependency chain: which step’s output does each other step need as input?

A teacher wants an algorithm that identifies students who scored above the class average, then returns their names in alphabetical order.

Algorithm Steps
Step A: Calculate each student’s individual average score across all assignments
Step B: Compute the class average (mean of all individual averages from Step A)
Step C: Keep only students whose individual average > class average
Step D: Sort the remaining student names alphabetically
A
individual
averages
→ needs A →B
class
average
→ needs B →C
filter above
average
→ needs C →D
sort
names
I. A → B → C → D
II. B → A → C → D
III. A → C → B → D
IV. A → B → D → C

Which sequence correctly produces an alphabetical list of students who scored above the class average?

10
When Does Convert Lock the Data?
HardAlgorithm Step Ordering
Watch for: Once Convert runs, the data becomes a string. Can you still Sort or Filter a string the same way you sort a list of numbers?

A programmer wants an algorithm that takes a list of numbers and returns a formatted string of perfect squares in order, separated by commas.
Example: [16, 7, 4, 25, 3, 9] → “4, 9, 16, 25”

Algorithm Steps
Filter: Keep only numbers that are perfect squares (1, 4, 9, 16, 25, …)
Sort: Sort the remaining numbers from least to greatest
Convert: Join the list of numbers into a single comma-separated string
I. Filter → Sort → Convert
II. Sort → Filter → Convert
III. Filter → Convert → Sort
IV. Convert → Filter → Sort

Which of the following correctly identifies all sequences that produce the correct result?

Get in Touch

Whether you're a student, parent, or teacher — I'd love to hear from you.

Just want free AP CS resources?

Enter your email below and check the subscribe box — no message needed. Students get daily practice questions and study tips. Teachers get curriculum resources and teaching strategies.

Typically responds within 24 hours

Message Sent!

Thanks for reaching out. I'll get back to you within 24 hours.

🏫 Welcome, fellow educator!

I offer curriculum resources, practice materials, and study guides designed for AP CS teachers. Let me know what you're looking for — whether it's classroom materials, a guest speaker, or Teachers Pay Teachers resources.

Email

[email protected]

📚

Courses

AP CSA, CSP, & Cybersecurity

Response Time

Within 24 hours

Prefer email? Reach me directly at [email protected]