AP CSP Filtering Sorting Practice
AP CSP Filtering, Sorting & Boolean Expressions
Big Idea 3: Algorithms & Programming — Boolean Logic, Filter/Sort Ordering & Algorithm Step Sequencing
Section 1: Boolean Expressions
Each question shows a spreadsheet. Write the correct AND/OR filter condition.
(day = "Friday") AND (day = "Saturday")
day field holds one value. It can never equal two different strings simultaneously. This expression is always false — nothing is ever counted.(day = "Friday") OR (day = "Saturday")
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.
| 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
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?
| 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
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?
| 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
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?
| 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
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?
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
Which of the sequences correctly places the youngest Marketing employee in 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
Select two sequences that correctly place the most expensive available furniture item with a listed price in row 1.
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
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.
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”].
Executing which of the following sequences will produce the correct sorted list of unique domain names?
A teacher wants an algorithm that identifies students who scored above the class average, then returns their names in alphabetical order.
individual
averages→ needs A →B
class
average→ needs B →C
filter above
average→ needs C →D
sort
names
Which sequence correctly produces an alphabetical list of students who scored above the class average?
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”
Which of the following correctly identifies all sequences that produce the correct result?
Practice Complete!
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.
Message Sent!
Thanks for reaching out. I'll get back to you within 24 hours.
Prefer email? Reach me directly at [email protected]