Ap Csa 2018 Frq 2 Wordpairlist

FRQ Archive2018 FRQs › FRQ 2: WordPairList
2018 AP CSA • ArrayList

AP CSA 2018 FRQ 2: WordPairList

Complete solution, scoring rubric, and walkthrough — verified from the official College Board PDF

9 Points Medium Unit 4
Question Type ArrayList
Skills Tested Nested loops for all i
Difficulty Medium
Recommended Time 22 minutes

What This Problem Asks

2018 AP CSA FRQ 2 WordPairList asks students to write a constructor (nested inumMatches (count pairs where both strings equal).

What This FRQ Tests

This FRQ tests Unit 4: ArrayList and Unit 2 nested loops.

Official Question & PDF

Download Full FRQ PDF →

PDF cannot display on this device. Open PDF directly →

Timer 22:00

Provided Code

public class WordPairList { private ArrayList allPairs; public WordPairList(String[] words) { } public int numMatches() { } }

Part A — 5 Points

Write the WordPairList constructor: initialize allPairs, add WordPair(words[i], words[j]) for all valid i < j.

Write Your Solution

Drag corner to expand ▽

 

Scoring Rubric (Part A — 5 points)

+1 Initializes allPairs as a new ArrayList
+1 Outer loop iterates 0 to words.length-1
+1 Inner loop iterates from i+1 to words.length-1
+1 Creates WordPair with words[i] and words[j]
+1 Adds each pair to allPairs (algorithm)

Solution

public WordPairList(String[] words)
{
    allPairs = new ArrayList();
    for (int i = 0; i < words.length; i++)
    {
        for (int j = i + 1; j < words.length; j++)
        {
            allPairs.add(new WordPair(words[i], words[j]));
        }
    }
}

Part B — 4 Points

Write numMatches: return the count of WordPair objects where getFirst().equals(getSecond()).

Write Your Solution

Drag corner to expand ▽

 

Scoring Rubric (Part B — 4 points)

+1 Traverses allPairs ArrayList
+1 Calls getFirst() and getSecond()
+1 Compares using equals
+1 Returns correct count (algorithm)

Solution

public int numMatches()
{
    int count = 0;
    for (WordPair wp : allPairs)
    {
        if (wp.getFirst().equals(wp.getSecond()))
        {
            count++;
        }
    }
    return count;
}

Common Mistakes to Avoid

Forgetting to initialize allPairs = new ArrayList()

Without initialization, allPairs is null and add() throws NullPointerException.

Exam Tips

Always initialize the ArrayList BEFORE adding to it.
Inner loop starts at j=i+1, not j=0.

Scoring Summary

Part Method Points
Part A Write 5
Part B Write 4
Total 9

Want the Complete 2018 FRQ Solutions?

Browse all past AP CSA FRQs with full solutions and scoring breakdowns.

FRQ Archive →

Related FRQs

ArrayList2021 FRQ 3: ClubMembers — ArrayList add and backward removal

Study the Concepts

Unit 4 Study Guide →

Struggling with FRQs? Get 1-on-1 Help

Work directly with Tanner — AP CS teacher with 11+ years experience and 1,845+ verified tutoring hours. 54.5% of students score 5s (vs. 25.5% national average).

5.0Rating (451+ reviews)
1,845+Verified Hours
54.5%Score 5s

Book a Session ($150/hr) →

5-session packages at $125/hr. Venmo, Zelle, PayPal, or credit card.

Frequently Asked Questions

What does 2018 FRQ 2 WordPairList test?

Nested i

Why must the constructor initialize allPairs?

Without allPairs = new ArrayList(), the field is null and add() throws NullPointerException.

Why does the inner loop start at i+1?

Starting at i+1 ensures each pair is added once with no self-pairs or duplicates.

How many points is 2018 FRQ 2 worth?

9 points: 5 for Part A (constructor) and 4 for Part B (numMatches).

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]