Skip to content

AP Computer Science Principles

AP Computer Science Principles introduces students to the foundational concepts of computer science and computational thinking. The course emphasizes creativity, collaboration, and problem-solving.

  • Duration: 2 hours 45 minutes
  • Sections:
    • Section I: 74 multiple-choice questions (1 hour 30 minutes)
    • Section II: Performance task (submitted separately)
  • Score: 1-5 (credit policy is per-institution: most state universities grant credit for 3+; selective colleges commonly require 4-5 or award placement instead)
Big IdeaWeightDescription
Creative Development10-15%Collaboration, program design, abstraction
Data15-20%Binary data, data compression, using data
Algorithms20-25%Algorithm development, efficiency, correctness
Programming30-35%Variables, control structures, procedures
Computing Systems and Networks10-15%Internet, cybersecurity, parallel computing
Impact of Computing10-15%Beneficial/harmful effects, digital divide

Computers store data in binary (base-2) using 0s and 1s.

# Decimal to Binary
def decimal_to_binary(n):
if n == 0:
return "0"
binary = ""
while n > 0:
binary = str(n % 2) + binary
n = n // 2
return binary
# Binary to Decimal
def binary_to_decimal(binary):
decimal = 0
for i, bit in enumerate(reversed(binary)):
decimal += int(bit) * (2 ** i)
return decimal
# Examples
print(decimal_to_binary(42)) # "101010"
print(binary_to_decimal("101010")) # 42
  • Run-Length Encoding (RLE): Replace consecutive identical values with count
  • Huffman Coding: Variable-length codes based on frequency
# Run-Length Encoding
def rle_compress(data):
compressed = []
i = 0
while i < len(data):
count = 1
while i + count < len(data) and data[i] == data[i + count]:
count += 1
compressed.append((data[i], count))
i += count
return compressed
# Example
data = "AAABBBCCDDDDD"
print(rle_compress(data)) # [('A', 3), ('B', 3), ('C', 2), ('D', 5)]
  • JPEG: Image compression using DCT
  • MP3: Audio compression using psychoacoustic models
  • Video compression: Frame differencing, motion estimation

Layer 4: Application (HTTP, FTP, SMTP, DNS)
Layer 3: Transport (TCP, UDP)
Layer 2: Internet (IP, ICMP, ARP)
Layer 1: Network Access (Ethernet, Wi-Fi)
GET /index.html HTTP/1.1
Host: www.example.com
User-Agent: Mozilla/5.0
Accept: text/html
HTTP/1.1 200 OK
Content-Type: text/html
Content-Length: 1234
<html>...</html>
  1. Malware: Viruses, worms, trojans, ransomware
  2. Phishing: Fake emails/sites to steal credentials
  3. DDoS: Overwhelm servers with traffic
  4. SQL Injection: Insert malicious SQL queries
  5. XSS: Inject malicious scripts into web pages
  1. Encryption: SSL/TLS, AES, RSA
  2. Authentication: Passwords, biometrics, 2FA
  3. Authorization: Access control, permissions
  4. Firewalls: Filter network traffic
  5. Updates: Patch vulnerabilities

# Python Variables
name = "Alice" # String
age = 16 # Integer
height = 5.5 # Float
is_student = True # Boolean
# Lists (dynamic arrays)
grades = [90, 85, 92, 88]
# Dictionaries (key-value pairs)
student = {
"name": "Alice",
"age": 16,
"grades": [90, 85, 92]
}
# If-Else
if age >= 18:
print("Adult")
elif age >= 13:
print("Teenager")
else:
print("Child")
# For Loop
for i in range(10):
print(i)
# While Loop
count = 0
while count < 10:
print(count)
count += 1
# Try-Except (Error Handling)
try:
result = 10 / 0
except ZeroDivisionError:
print("Cannot divide by zero")
# Function Definition
def calculate_average(numbers):
"""Calculate the average of a list of numbers."""
if not numbers:
return 0
return sum(numbers) / len(numbers)
# Function Call
grades = [90, 85, 92, 88]
avg = calculate_average(grades)
print(f"Average: {avg:.2f}")
# Recursive Function
def factorial(n):
"""Calculate factorial recursively."""
if n <= 1:
return 1
return n * factorial(n - 1)

# Sequencing: Execute steps in order
def make_sandwich():
get_bread()
add_spread()
add_filling()
close_sandwich()
# Selection: Choose between options
def get_grade(score):
if score >= 90:
return "A"
elif score >= 80:
return "B"
else:
return "C"
# Iteration: Repeat steps
def sum_list(numbers):
total = 0
for num in numbers:
total += num
return total
# O(1) - Constant Time
def get_first(items):
return items[0]
# O(n) - Linear Time
def find_max(items):
max_val = items[0]
for item in items:
if item > max_val:
max_val = item
return max_val
# O(n²) - Quadratic Time
def bubble_sort(items):
n = len(items)
for i in range(n):
for j in range(0, n-i-1):
if items[j] > items[j+1]:
items[j], items[j+1] = items[j+1], items[j]
return items
  • O(1): Fixed extra space
  • O(n): Space proportional to input
  • O(n²): Space for 2D structures

  1. Volume: Large amounts of data (terabytes, petabytes)
  2. Velocity: Fast generation and processing
  3. Variety: Different formats (structured, unstructured)
# Data Analysis with Python
import pandas as pd
# Load data
df = pd.read_csv("data.csv")
# Basic statistics
print(df.describe())
# Filtering
high_scores = df[df["score"] > 90]
# Grouping
average_by_group = df.groupby("group")["score"].mean()
  1. Supervised Learning: Labeled training data
  2. Unsupervised Learning: Find patterns in unlabeled data
  3. Reinforcement Learning: Learn from rewards/punishments
# Linear Regression (simplified)
def predict(x, slope, intercept):
return slope * x + intercept
# Training data
x = [1, 2, 3, 4, 5]
y = [2, 4, 5, 4, 5]
# Simple gradient descent
slope = 0
intercept = 0
learning_rate = 0.01
for _ in range(1000):
for xi, yi in zip(x, y):
prediction = predict(xi, slope, intercept)
error = prediction - yi
slope -= learning_rate * error * xi
intercept -= learning_rate * error
print(f"Slope: {slope:.2f}, Intercept: {intercept:.2f}")

  • Communication: Email, social media, video calls
  • Education: Online learning, educational apps
  • Healthcare: Medical records, telemedicine
  • Transportation: GPS, ride-sharing, autonomous vehicles
  • Entertainment: Streaming, gaming, virtual reality
  • Privacy: Data collection, surveillance
  • Security: Hacking, identity theft
  • Employment: Automation, job displacement
  • Health: Screen addiction, sedentary lifestyle
  • Environment: E-waste, energy consumption
  • Access: Not everyone has internet or devices
  • Skills: Not everyone knows how to use technology
  • Affordability: Technology can be expensive
  • Literacy: Understanding how to use technology effectively

  1. Program Design: Document your program’s purpose and design
  2. Development Process: Show iterative development
  3. Program Functionality: Program must be complete and functional
  4. Video: 1-minute video demonstrating your program
  1. Choose a meaningful project - Solve a real problem
  2. Document your process - Show iterations and improvements
  3. Test thoroughly - Demonstrate all functionality
  4. Practice your video - Be clear and concise

Question 1: What is the decimal equivalent of binary 1010? A) 8 B) 10 C) 12 D) 14

Answer: B) 10 (1×8 + 0×4 + 1×2 + 0×1)

Question 2: Which compression method is lossy? A) Run-Length Encoding B) Huffman Coding C) JPEG D) ZIP

Answer: C) JPEG (images lose some quality)

Question 3: What is the time complexity of binary search? A) O(n) B) O(log n) C) O(n²) D) O(1)

Answer: B) O(log n)

  1. Understand concepts - Don’t just memorize
  2. Practice coding - Build real programs
  3. Review big ideas - Focus on major themes
  4. Take practice exams - Familiarize with format
  5. Discuss with others - Explain concepts to learn better