Advanced Placement Computer Science A focusing on Java programming and object-oriented design.
Not all code is created equal! Some algorithms solve problems faster than others.
Big O notation describes how the runtime of an algorithm grows as the input size increases.
Sorting puts elements in order. Common algorithms include:
// Simple selection sort
for (int i = 0; i < arr.length - 1; i++) {
int min = i;
for (int j = i+1; j < arr.length; j++) {
if (arr[j] < arr[min]) min = j;
}
int temp = arr[i];
arr[i] = arr[min];
arr[min] = temp;
}
Efficient algorithms save time and make programs run smoothly—essential for apps, games, and websites!
Comparing \( O(n) \) and \( O(n^2) \) algorithms for sorting a list.
Using selection sort to order student grades.
Algorithm analysis helps you write faster, more efficient code.