BIG-IDEAS

AP CSA Unit 1

Algorithm

An algorithm is a step by step process to follow when completing a task or solving a problem.

It is helpful to be very specific and detailed when writing algorithms.

Data Types

Integers are whole numbers, doubles are decimals, booleans are true/false.

Printing

Use System.out.print() to print in Java.

Comments

Use // for comments.

Documentation

Documentation helps explain how code works—APIs are instruction manuals for code.

Java Keywords

Skill #2 – API

Documentation describing available methods in libraries.

1.5–1.9 Incrementing a Variable

a = a + 1;
a += 1;
a++;

Input

Scanner in = new Scanner(System.in);
int number = in.nextInt();

AP CSA Unit 2 – Big Idea 2

2.1 Algorithms, Selection, and Iteration

2.2 Designing Algorithms

if(score >= 60) System.out.println("Pass");

2.3 Accumulator Pattern

int sum = 0;
for(int i = 1; i <= 100; i++) sum += i;

AP CSA Unit 3 – Big Idea 3

3.1 Abstraction and Program Design

3.2 Impact of Program Design

3.3 Anatomy of a Class

3.4 Constructors

3.5 Methods

3.6 Passing & Returning Objects

3.7 Static

3.8 Scope

3.9 this Keyword

AP CSA Unit 4 – Big Idea 4 (Data & Arrays)

4.1 Ethical and Social Issues Around Data Collection

4.2 Introduction to Using Data Sets

4.3 Array Creation and Access

int[] numbers;
numbers = new int[5];
int[] numbers = new int[5];
int[] numbers = {1, 2, 3, 4};

4.4 Array Traversals

for(int i = 0; i < arr.length; i++) {
    System.out.println(arr[i]);
}
for(int value : arr) {
    System.out.println(value);
}

4.5 Implementing Array Algorithms

public static int find(int[] arr, int target) {
    for(int i = 0; i < arr.length; i++) {
        if(arr[i] == target) {
            return i;
        }
    }
    return -1;
}
for(int i = 0; i < arr.length; i++) {
    arr[i] *= 2;
}
for(int i = 0; i < arr.length; i++) {
    if(arr[i] < 0) {
        arr[i] = 0;
    }
}

4.6 Using Text Files

4.7 Wrapper Classes

int → Integer
double → Double
char → Character
boolean → Boolean

4.8 ArrayList Methods

ArrayList nums = new ArrayList<>();

nums.add(5);        // add to end
nums.add(0, 3);     // insert at index
nums.get(0);        // retrieve value
nums.set(1, 10);    // replace value
nums.remove(0);     // remove element
nums.size();        // number of elements
nums.clear();       // remove all elements

4.9 ArrayList Traversals

for(int i = 0; i < list.size(); i++) {
    System.out.println(list.get(i));
}
for(int value : list) {
    System.out.println(value);
}

4.10 Implementing ArrayList Algorithms

for(int i = list.size() - 1; i >= 0; i--) {
    if(list.get(i) < 0) {
        list.remove(i);
    }
}

4.11 2D Array Creation and Access

int[][] grid = new int[3][4];

grid[0][1] = 5;

4.12 2D Array Traversals

for(int r = 0; r < grid.length; r++) {
    for(int c = 0; c < grid[r].length; c++) {
        System.out.println(grid[r][c]);
    }
}

4.13 Implementing 2D Array Algorithms

4.14 Searching Algorithms

for(int i = 0; i < arr.length; i++) {
    if(arr[i] == target)
        return i;
}

4.15 Sorting Algorithms

4.16 Recursion

public int factorial(int n) {
    if(n == 0)
        return 1;

    return n * factorial(n - 1);
}

4.17 Recursive Searching and Sorting