1.
Introduction to Computer Science
● Computer Science: The study of algorithms, data structures, programming languages,
and the principles behind computing systems.
● Programs: Sequences of instructions that tell a computer what to do.
● Software vs. Hardware:
○ Software: Programs and applications (e.g., browsers, games).
○ Hardware: Physical components (e.g., CPU, memory).
2. Data Types and Variables
● Primitive Data Types:
○ int: Integer (e.g., 3, -15)
○ double: Floating-point number (e.g., 3.14, -0.001)
○ char: Single character (e.g., 'a', 'Z')
○ boolean: True or false (e.g., true, false)
○ String: Sequence of characters (e.g., "Hello")
● Variables: Store data values, declared with a type (e.g., int x = 5;).
3. Control Structures
● Conditional Statements:
○ if, else if, else: Used for decision-making (e.g., if (x > 5) { } else { }).
○ switch: Allows multiple cases for decision-making.
● Loops:
for loop: Repeats code a specific number of times.
java
Copy code
for (int i = 0; i < 10; i++) { }
while loop: Repeats as long as a condition is true.
java
Copy code
while (x < 10) { }
○
4. Methods and Functions
● Method: A block of code that performs a specific task, defined with a return type and
parameters.
○ Syntax: returnType methodName(parameters) { }
Example:
java
Copy code
public int add(int a, int b) { return a + b; }
○
● Parameters: Variables passed into methods to perform operations.
5. Object-Oriented Programming (OOP)
● Classes and Objects:
○ Class: A blueprint for creating objects (e.g., class Dog { }).
○ Object: An instance of a class (e.g., Dog myDog = new Dog();).
● Key Principles:
○ Encapsulation: Hiding implementation details, exposing only necessary parts.
○ Inheritance: Creating a new class based on an existing class.
○ Polymorphism: Using the same method name for different functions (method
overloading or overriding).
○ Abstraction: Simplifying complex systems by exposing only essential features.
6. Arrays and ArrayLists
● Array: A fixed-size collection of elements.
○ Example: int[] arr = {1, 2, 3, 4};
● ArrayList: A dynamic array that can grow in size.
Example:
java
Copy code
ArrayList<String> list = new ArrayList<>();
list.add("Hello");
○
7. Sorting and Searching Algorithms
● Sorting Algorithms:
○ Selection Sort: Repeatedly selects the smallest element and moves it to the
front.
○ Bubble Sort: Compares adjacent elements and swaps them if they’re in the
wrong order.
● Searching Algorithms:
○ Linear Search: Checks each element in a list for a match.
○ Binary Search: Efficient search on a sorted list by repeatedly dividing the range
in half.
8. Recursion
● Recursion: A method where the solution to a problem depends on solving smaller
instances of the same problem.
Example:
java
Copy code
public int factorial(int n) {
if (n == 0) return 1;
return n * factorial(n - 1);
}
9. Big O Notation (Algorithm Efficiency)
● Big O: Describes the efficiency of an algorithm in terms of time or space as the input
size grows.
○ O(1): Constant time.
○ O(n): Linear time.
○ O(n^2): Quadratic time.
10. AP Exam Tips
● Practice coding: Familiarize yourself with Java syntax and logic.
● Understand problem-solving: Break problems into smaller parts, write pseudocode,
and test edge cases.
● Focus on key algorithms: Sorting, searching, recursion, and basic data structures.