Skip to main content
← AP CSA Study Guide

Unit 8 · Exam-weighted

2D Arrays, Algorithms, and Data

The final unit combines grid traversal, the standard search and sort algorithms with their efficiency comparison, and the data topics that close the course.

What a strong answer looks like

A strong Unit 8 answer names which loop controls rows and which controls columns, and compares algorithms by how their work grows rather than by stopwatch.

Topics in this unit

1

2D Array Basics

Practice this topic →

Know

A 2D array is an array of arrays. The first index selects the row and the second the column, and rows need not all be the same length.

Apply

Use the outer length for the row count and each row’s own length for its column count.

Watch out

Assuming every row has the same length, which fails on a ragged array.

Study move

Declare a 2D array and state the expression giving the number of columns in a specific row.

2

2D Array Traversal

Practice this topic →

Know

Row-major traversal puts the row loop outside and the column loop inside, visiting each row completely before moving on.

Apply

Name which loop controls rows before tracing, then count visits as the product of the bounds.

Watch out

Swapping the indexes, which either transposes the result or throws when the array is not square.

Study move

Trace a row-major sum and then a column-major sum of the same grid.

3

Linear and Binary Search

Practice this topic →

Know

Linear search works on any order; binary search requires sorted data and halves the remaining range each step.

Apply

Check that data is sorted before choosing binary search, and compute the midpoint safely.

Watch out

Applying binary search to unsorted data, which returns a confidently wrong answer rather than failing.

Study move

Trace a binary search on a sorted array, recording the range at each step.

4

Sorting and Efficiency

Practice this topic →

Know

Selection and insertion sort compare and move elements repeatedly; their cost grows with the square of the input, while merge sort grows far more slowly.

Apply

Compare algorithms by counting comparisons as the input grows, not by timing one run.

Watch out

Claiming an algorithm is fast from one small example. Growth rate, not a single measurement, is what is being compared.

Study move

Count the comparisons insertion sort makes on already-sorted and reverse-sorted input.

5

Text Files and Scanner

Practice this topic →

Know

Scanner reads input token by token or line by line, and the reading pattern must match the shape of the data.

Apply

Check whether more input remains before reading, and match the read method to the data type.

Watch out

Mixing token and line reads, which leaves a partial line behind and misaligns everything after it.

Study move

Describe the reads needed for a file where each line holds a name and a number.

6

Data and Its Implications

Practice this topic →

Know

Programs that collect data carry consequences for the people described by it, including privacy and the risk of encoding existing bias.

Apply

For any program handling personal data, state what is collected, why it is needed, and who can see it.

Watch out

Treating data questions as opinion. They expect reasoning about specific, identifiable consequences.

Study move

Take a small program that stores student records and list what it collects and what could go wrong.

Emphasized in this unit

Connections and techniques that receive extra attention in this unit.

  • Naming which loop controls rows before tracing a grid
  • Checking the sorted precondition before choosing binary search
  • Comparing algorithms by growth rather than by a single timing

Varies by course

Related topics some schools attach to this unit and others leave out. Covered on request rather than assumed.

  • Ragged arrays. Some courses treat 2D arrays as strictly rectangular; Java permits rows of differing length.
  • Recursion in sorting. Merge sort is discussed at different depths depending on the course.
  • File writing. Often taught in class, though the exam concerns reading.

Mastery checklist

  • Give the row count and the column count of a specific row.
  • Trace a row-major traversal of a grid.
  • State the precondition binary search requires.
  • Compare two sorts by how their work grows.
  • Match a Scanner reading pattern to a described file.
  • Name a concrete privacy consequence of a data-collecting program.

Check yourself

  • What breaks if you assume every row of a 2D array is the same length?
  • Why does binary search fail silently on unsorted data?
  • Why is a single timing a poor way to compare two algorithms?

Modeling drill

Write a traversal that finds the largest value in a 2D array and reports its row and column, then state its behavior on a ragged array.

Row-majorRagged arrayBinary searchPreconditionGrowth rateScannerToken