AP Computer Science Principles Notes

AP Computer Science Principles Course Study Guide

Main Ideas

  • AP Computer Science Principles (CSP) teaches computational thinking, conventions, and concepts central to computer science.

  • The course is organized around five ideas throughout the whole course to build a base for prospective computer science courses in the future.

  • Main ideas:

    • Creativity: Important part of innovation.

    • Abstractions: Minimize extra details to focus on pertinent information and helps manage complexity.

    • Data/Information: Input for computing; computation translates raw data into consumable information.

    • Algorithms: Used to develop solutions to computational problems.

    • Programming: Creation of software enables problem-solving and is directly related to creating algorithms.

    • The Internet: Has a heavy effect on society, so it is important to understand how it is built and functions to analyze concerns such as cybersecurity.

    • Global Impact: Computation has changed communication and problem-solving.

Unit 1: The Internet Vocab

  • The Internet: A group of computers and servers that are connected.

  • Prototype: An original model on which later versions are patterned

  • Innovation: Something new, a change; the act of introducing a new method, idea, device, etc.

  • Binary: A way of representing information using only two options.

  • Bit: A contraction of "Binary Digit"; the single unit of information in a computer, typically represented as a 0 or 1

  • Bandwidth: Transmission capacity measure by the bit rate

  • Bit rate: The number of bits that are conveyed or processed per unit of time. e.g. 8 bits/sec.

  • Latency: Time it takes for a bit to travel from its sender to its receiver.

  • Protocol: A set of rules governing the exchange or transmission of data between devices.

  • Abstraction: A simplified representation of something more complex.

  • ASCII (American Standard Code for Information Interchange): Universally recognized raw text format that any computer can understand.

  • IP Address: A number assigned to any item that is connected to the Internet.

  • Packets: Small chunks of information that have been carefully formed from larger chunks of information.

  • Network Redundancy: Having multiple backups to ensure reliability during cases of high usage or failure.

  • Router: A type of computer that forwards data across a network

  • DNS (Domain Name System): Translates domain names (like example.com) to IP addresses (like 93.184.216.34)

  • IETF (Internet Engineering Task Force): Develops and promotes voluntary Internet standards and protocols, in particular the standards that comprise the Internet protocol suite (TCP/IP).

  • Request for Comments: How standards and protocols are defined and published for all to see on the IETF website.

  • HTTP (HyperText Transfer Protocol): The protocol used for transmitting web pages over the Internet

  • TCP (Transmission Control Protocol): Provides reliable, ordered, and error-checked delivery of a stream of packets on the internet. TCP is tightly linked with IP and usually seen as TCP/IP in writing.

  • URL (uniform resource locator): An easy-to-remember address for calling a web page like www.code.org

  • SSL (Secure Sockets Layer): Standard security technology for establishing an encrypted link between a web server and a browser.

  • SSL Certificate: To create an SSL certificate, a web server requires an SSL certificate that may be obtained from a Certification Authority (CA).

  • TLS (Transport Layer Security): A cryptographic protocol that provides end-to-end communication security over networks and is widely used for internet connections and online transactions. IETF standard to prevent tampering and message forgery and the successor to SSL.

  • SMTP (Simple Mail Transfer Protocol): High-level protocol for formatting and sending email messages between mail servers.

  • POP (Post Office Protocol): IMAP (Internet Message Access Protocol) are used to retrieve emails on the server's side

  • HTML (Hypertext Markup Language): A computer code used to tell a web page how to look.

  • Net Neutrality: The principle that all Internet traffic should be treated equally by Internet Service Providers.

Sending Information
  • The Internet works like a postal service that ships binary information.

    • Binary information is made of bits - any pair of opposites (like on or off, or yes or no)

    • Bits are sent in three ways: light, electricity, and wirelessly

      • Copper wire:

        • Pros: Cheap

        • Cons: Signal loss

      • Fiber optic cable:

        • Pros: Fast, no signal loss

        • Cons: Expensive, hard to work with

      • Radio waves:

        • Pros: Mobile

        • Cons: Short range

    • Bits are usually represented as either a 1 or a 0; this system of numbers is called binary or base 2 (since there are 2 bases).

Reading Binary
  • Binary is a system of counting that has 2 bases unlike the decimal system that is used commonly that has 10 bases.

  • Binary is an on or off system, which means that a bit is either on or off.

  • Binary is calculated from left to right, and each digit is 2 to the power of n (the number of spaces to the left)

  • Example 1: 0101 1001

    1. Number all the digits from left to right (7654 3210)

    2. Each digit is 2 to the power above (2^7 2^6 2^5 2^4 2^3 2^2 2^1 2^0)

    3. Disregard all digits with a 0 since they are “off” (2^6 2^4 2^3 2^0)

    4. Add all the numbers together (64+16+8+1)

    5. The answer is 89

  • Example 2: 10 1110

    1. Number all the digits from left to right (54 3210)

    2. Each digit is 2 to the power above (2^5 2^4 2^3 2^2 2^1 2^0)

    3. Disregard all digits with a 0 since they are “off” (2^5 2^3 2^2 2^1)

    4. Add all the numbers together (32+8+4+2)

    5. The answer is 46

  • ASCII (American Standard Code for Information Interchange) is written using binary with 8 bits or a byte representing an ASCII character.

How does information travel?
  1. All information to be sent over the internet is cut into smaller packets, numbered to keep the order of the information.

  2. Information is sent over the internet in these smaller packages.

    • Information used to reconstruct the file is on the outside of the packages. (sender, receiver, source file, packet number)

    • Packets travel on their own through different routers trying to find the fastest path always. Having extra routers for this purpose is called network redundancy, which makes the system more fault-tolerant.

  3. TCP/IP process the packet by extracting and merging its inside data with the data from the other packets from the same file, in the correct order, in order to rebuild the file from its packets.

    • If there is missing/ incorrect data, TCP/IP from this computer will send a message to TCP/IP on the sender computer, asking to resend a particular packet.

Unit 2: Digital Information Vocab

  • Heuristic: A problem-solving approach (algorithm) to find a satisfactory solution where finding an optimal or exact solution is impractical or impossible.

  • Lossless Compression: A data compression algorithm that allows the original data to be perfectly reconstructed from the compressed data.

  • Lossy Compression: Irreversible compression; a data compression method that uses inexact approximations, discarding some data to represent the content. Most commonly seen in image formats like .jpg.

  • Image: A type of data used for graphics or pictures.

  • Metadata: Data that describes other data. ex. a digital image may include metadata that describe the size of the image, number of colors, or resolution.

  • Pixel: Short for "picture element", the fundamental unit of a digital image, typically a tiny square or dot that contains a single point of the color of a larger image.

  • Hexadecimal: A base-16 number system that uses sixteen distinct symbols 0-9 and A-F to represent numbers from 0 to 15.

  • RGB: This color model uses varying intensities of (R)ed, (G)reen, and (B)lue light are added together in to reproduce a broad array of colors.

  • Byte: 8 bits of data; the standard fundamental unit (or "chunk size") underlying most computing systems today.

  • File extension: A group of letters occurring after a period in a file name, indicating the format of the file like .png

  • Abstraction: A simplified representation of something more complex. they allow you to hide details to help you manage complexity, focus on relevant concepts, and reason about problems at a higher level

  • Encoding: The processing of information into the memory system

  • Decoding: Interpreting and trying to make sense of the message

  • Resolution: The dimensions by which you can measure how many pixels are on a screen

  • Density: The number of pixels in a certain space

  • Zip folders: A computer file whose contents of one or more files are compressed for storage or transmission.

  • Image file: A file that contains graphic data.

  • Text file: A file that contains only text without any special formatting.

  • Favicon: A small, customized icon shown in the address bar next to the URL or the Favorites menu when a site is bookmarked.

How to read Hexadecimal numbers
  • Hex is a system of counting that has 16 bases unlike the binary system that we use to send information and has 2 bases.

    • It uses the letters A-F since there are only 10 numbers

  • Hex is also calculated from left to right and each digit is the number to the power of n (the number of spaces to the left)

  • Example 1: C0D5

    1. Starting with 0, number all the digits from left to right ( 3210)

    2. Each digit is the number times 16 to the power above (C16^3 016^2 D16^1 516^0$)

    3. Disregard all digits with a 0 since they are “off”; note that A-F correspond to 10-15 respectively (1216^3 1316^1 5*16^0$)

    4. Add all the numbers together (49152+208+5)

    5. The answer is 49365

  • Example 2: 7F

    1. Starting with 0, number all the digits from left to right (10)

    2. Each digit is 2 to the power above (716^1 F16^0$)

    3. Disregard all digits with a 0 since they are “off”; note that A-F correspond to 10-15 respectively (716^1 1516^0$)

    4. Add all the numbers together (112+15)

    5. The answer is 127

How to encode a color
  • RGB is the color system used in computer screens, it is different from printers which commonly use CMYK

    • CMYK is a subtractive color scheme that uses the colors to tint the light which makes the colors darker as you mix them. All the colors mixed added to a constant (k) makes black

    • RBG is an additive color scheme that uses colored light (which is why it's commonly used in screens) so that the colors get lighter as you mix them. All the colors added together to make white

  • In a computer, colors are usually coded as a six-digit hex number.

    • Ex. #4G 76 F0

    • Since the computer uses RBG, there are two digits for each value

      • So 4G is the amount of red light, 76 is the amount of green light, and F0 is the amount of blue light

      • Some numbers to remember:

        • #000000 is black

        • #FFFFFF is white

        • #FF0000 is red

        • #00FF00 is green

        • #0000FF is blue

Units
  • Bit

  • Nybble: 4 bits

  • Byte: 8 bits

  • Kilobyte: 1,000 (10^3) bytes

  • Megabyte: 1,000,000 (10^6) bytes

  • Gigabyte: 1,000,000,000 (10^9) bytes

  • Terabyte: 1,000,000,000,000 (10^{12}) bytes

  • Petabyte: 1,000,000,000,000,000 (10^{15}) bytes

  • Exabyte: 1,000,000,000,000,000,000 (10^{18}$$) bytes

Files and Compression
  • Two types of compression:

    • Lossy compression is irreversible and erases data by using inexact approximations

      • Ex. .jpg, .mp3

    • Lossless compression is a compression algorithm that records patterns in a dictionary and allows the data to be reconstructed perfectly

      • Ex. .png, .wav

Relevant File Types
  • JPEG (.jpg):

    • Audio; Lossy

    • Created by the joint photographic experts group in 1992; intended to be free; some patent disputes

  • MP3 (.mp3):

    • Audio; Lossy

    • Created by the moving picture experts group in 1993; free; many companies have tried to claim ownership

  • PNG (.png):

    • Image; Lossless

    • Created by the PNG development group in 1996 and designed to replace the GIF; free

  • MP4 (.mp4):

    • Multimedia; Lossy

    • Created by the ISO/IEC and Motion Picture Experts Group; free

  • WAV (.wav):

    • Audio; Lossless

    • Created by IBM and Microsoft in 1991; free

Unit 3: Intro to Programming Vocab

  • Algorithm: A precise sequence of instructions for processes that can be executed by a computer and are implemented using programming languages.

  • Low level: A programming language that captures only the most primitive operations available to a machine. Anything that a computer can do can be represented with combinations of low-level commands

  • High-level programming language: A programming language with many commands and features designed to make common tasks easier to program. Any high-level functionality is encapsulated as combinations of low-level commands

  • Selection: A generic term for a type of programming statement (usually an if-statement) that uses a Boolean condition to determine, or select, whether or not to run a certain block of statements

  • Sequencing: Putting commands in the correct order so computers can read the commands

  • Function: A named group of programming instructions

  • API (application programming interface): A collection of commands made available to a programmer

  • Documentation: A description of the behavior of a command, function, library, API, etc

  • Library: A collection of commands/functions, typically with a shared purpose

  • Parameter: An extra piece of information that you pass to the function to customize it for a specific need

  • For Loop: A particular kind of looping construct provided in many languages. Typically, defines a counting variable that is checked and incremented on each iteration to loop a specific number of times

  • Loop: A programming construct that repeats a group of commands

  • Programming Language: A coding language used to dictate specific instructions to a computer

  • Programming Environment: A tool where you write and run computer programs

  • Debugging: Finding and fixing problems in your algorithm or program

  • Top-Down Design: A problem-solving approach (also known as stepwise design) in which you break down a system to gain insight into the subsystems that make it up

  • Camelcase: Multi-word function names are made a single word which begins in lowercase and uses uppercase letters to indicate the start of a new word

  • Iterate: To repeat to achieve, or get closer to, the desired goal

  • Turtle Programming: A classic method for learning programming with commands to control movement and drawing of an on-screen robot called a "turtle"

  • Blocks: Pieces of code that you use to solve a problem; in App Lab, they can be dragged from the toolbox menu to the workspace to create a program

  • Subgoal: Parts of a problem's solution (the overall goal); used so you can focus on figuring out which block(s) you need to solve each subgoal rather than trying to solve the whole problem at once

  • Efficiency: Achieving some desired outcome while minimizing wasted effort or resources

  • Abstraction: A simplified representation of something more complex

  • Iteration: "loop" by another name - the repetition of a statement, process, or procedure

Programming languages
  • Formalize language or commands that describe actions to make code.

  • Computers can perform many different tasks.

    • To write instructions, agree on the “code.”

    • Each action must have a precise, unambiguous meaning.

  • This is the basis of a programming language.

    • All programming languages are derived from the need to concisely give instructions to a machine.

To design an algorithm:
  1. Discover common instructions

    • Includes turning right, saving a number by changing a variable, jumping to a certain line in the instructions, etc.

  2. Agree on a minimal instruction set

    • Recognizing these commonalities can give you names to a few commands and agree about how they should be interpreted.

High vs Low level Programming languages
  • High-level programming languages are more programmer-friendly, which makes it easier to understand and debug

    • Ex. JavaScript,

  • Low-level languages are tough to understand and require a machine to operate; also not commonly used.

    • Ex. Machine Language

  • High-level languages also make use of abstractions to manage complexity

    • An abstraction is a simplified representation of something more complex.

    • Abstractions are helpful because it makes it so that you do not need to understand everything in complicated code.

      • Ex. The codes use functions in their programs to manage complexity by allowing you to use the function without needing to know how the function works or what code is in the function.

      • The parameters (size, red, green, blue) are helpful because they help generalize the solution which can make the function more versatile.

Variables
  • In programming, variables are used to hold information.

    • They essentially work like containers where you can change their value when you need to hold another number.

    • Variables may look like simple math, but it is not.

    • Ex.

      • x = 2

      • x = 5

      • x = x + 1

        • At first sight, might not make sense, but x is a variable (so remember it is like a container)

        • “=” is the assignment operator, so‘x=2’ means that you are assigning x the value of 2

        • The value of x is now 6 because x is assigned the value of 5 + 1 which is 6

Looping and Random Numbers
  • Looping is a programming construct that is used to repeat sections of code multiple times.

    • Ex. for (var i = 0; i < 4; i++)

    • For loops are loops that define a counting variable (var i = 0) that is checked (i < 4) and incremented ( i++) on each iteration to loop a specific number of times

  • Random number is a mathematical function that allows any value to be a random number within a maximum number and a minimum number.

    • Ex. moveTo(randomNumber(0,320), randomNumber(360,450))

    • The coordinates from the moveTo function were replaced by random numbers to place the image randomly

    • The max and min on the random number are the dimensions of the screen

Unit 4: Big Data and Privacy Vocab

  • Big Data: A broad term for datasets so large or complex that traditional data processing applications are inadequate

  • Moore's Law: A prediction made by Gordon Moore in 1965 that computing power will double every 1.5-2 years; it has remained more or less true ever since.

  • Caesar cipher: A technique for encryption that shifts the alphabet by some number of characters

  • Cipher: The generic term for a technique (or algorithm) that performs encryption

  • Cracking encryption: When you attempt to decode a secret message without knowing all the specifics of the cipher, you are trying to "crack" the encryption.

  • Decryption: A process that reverses encryption, taking a secret message and reproducing the original plain text

  • Encryption: A process of encoding messages to keep them secret, so only "authorized" parties can read it.

  • Random substitution cipher: An encryption technique that maps each letter of the alphabet to a randomly chosen other letters of the alphabet.

  • Computationally Hard: A "hard' problem for a computer is one in which it cannot arrive at a solution in a reasonable amount of time.

  • Asymmetric Encryption: Used in public-key encryption, it is a scheme in which the key to encrypt data is different from the key to decrypt.

  • Modulo: A mathematical operation that returns the remainder after integer division.

  • Private key: In an asymmetric encryption scheme the decryption key is kept private and never shared, so only the intended recipient has the ability to decrypt a message that has been encrypted with a public key.

  • Public key encryption: Used prevalently on the web, it allows for secure messages to be sent between parties without having to agree on, or share, a secret key. It uses an asymmetric encryption scheme in which the encryption key is made public, but the decryption key is kept private.

  • Antivirus software: Usually keeps big lists of known viruses and scans your computer looking for the virus programs in order to get rid of them.

  • DDoS attack: Distributed Denial of Service Attack. Typically a virus installed on many computers (thousands) activates at the same time and floods a target with traffic to the point the server becomes overwhelmed.

  • Firewall: Software that runs on servers (often routers) that only allows traffic through according to some set of security rules.

  • Phishing scam: A thief trying to trick you into sending them sensitive information. Typically these include emails about system updates asking you to send your username and password, social security number, or other things.

  • SSL/TLS: Secure Sockets Layer / Transport Layer Security - An encryption layer of HTTP that uses public-key cryptography to establish a secure connection.

  • Virus: A program that runs on a computer to do something the owner of the computer does not intend.

  • Digital divide: The gulf between those who have ready access to computers and the Internet and those who do not.

  • Worm: A standalone malware computer program that replicates itself in order to spread to other computers. It uses a computer network to spread itself, relying on security failures on the target computer to access it.

  • Vignere Cipher: A method of encrypting text by applying a series of Caesar ciphers based on the letters of a keyword.

  • Malware: Software that is intended to damage or disable computers and computer systems.

What is big data?
  • Big data is a large and complex dataset that is useful and can be used to help the world in many ways

    • A larger data set gives us access to much more information and more ways to analyze and use that information.

    • Examples:

      • A car collecting data on your normal driving patterns so that when someone else tries to drive, they need to input a password

      • Using images from biopsies to determine if cells are cancerous

The Digital Divide
  • The digital divide is the rift between those with reliable constant access to the internet and those who don’t.

    • Those who don’t are usually either senior citizens, have a lower income, or live in areas with less internet access.

    • It is more important now than ever before because of how rapidly the internet and internet use has become.

    • Examples:

      • A school that transitions to online learning and doesn’t provide anything to students who need internet/computer assistance

      • A city council that sends out an online survey to see which roads in the city have the most potholes/cracks and need to be filled up.

Ciphers
  • Caesar cipher- shifts the alphabet by a certain number to obtain a new alphabet

    • Ex. cipher => elrjgt (shifted by 2)

  • Vignere cipher- uses a series of Caesar ciphers based on a code word

    • Ex. cipher => eqeoii (keyword- cipher)

  • Random substitution cipher- plots each letter of the alphabet to another random letter

    • Ex. cipher => hednyuo

Encryption
  • Asymmetric encryption is when the key to encrypt a message is different from the private key used to decrypt the message.

  • Public key encryption is an asymmetric encryption scheme prevalent on the web.

    • It allows you to encrypt something with a key that’s accessible to the public, but to decrypt it, you would need a private key.

  • Encryption is very necessary because otherwise hacking other people/stealing their information would be too easy.

Hacking
  • Some of the most common hacking attacks include DNS spoofing, DDoS attacks, worms, and phishing scams.

    • DNS spoofing: when the Domain Name System is hacked to redirect online traffic to a certain website to an imposter website.

      • Ex. the attacker spoofs a DNS record to redirect all the traffic that relied on the correct DNS record to visit a fake website that the attacker has created to resemble the real site or a different site completely.

    • DDoS (Distributed Denial of Service) attacks: A virus installed on many computers activates at the same time and floods a target with traffic. DDoS is one of the oldest forms of cyber extortion attack

      • Ex. A virus causes thousands of computers to send so much internet traffic to a server to the point that legitimate users can't join

    • Phishing attack: a thief trying to trick you into sending them sensitive information.

      • Ex. You get an email from someone who is claiming to be your great aunt twice removed and wants to give you a million dollars. She asks for your bank account information so that she can transfer the money

Unit 5: Building Apps Vocab

  • Callback function: A function specified as part of an event listener; it is written by the programmer but called by the system as the result of an event trigger

  • Event: An action that causes something to happen

    • Ex. a mouse click

  • Event-driven program: A program designed to run blocks of code or functions in response to specified events

  • Event handling: An overarching term for the coding tasks involved in making a program respond to events by triggering functions.

  • Event listener: A command that can be set up to trigger a function when a particular type of event occurs on a particular UI element

  • UI elements: On-screen objects, like buttons, images, text boxes, pull down menus, screens and so on

  • User Interface (UI): The visual elements of a program through which a user controls or communicates with the application

  • Debugging: Finding and fixing problems in an algorithm or program

  • Data type: All values in a programming language have a "type" - such as a Number, Boolean, or String - that dictates how the computer will interpret it.

    • Ex. 7+5 is interpreted differently from "7"+"5"

  • Expression: Any valid unit of code that resolves to a value

  • Variable: A placeholder for a piece of information that can change

  • Equality operator: Is used for comparing two values, and returns a Boolean (true/false). Avoid confusion with the assignment operator "="; sometimes read "equal equal" (==)

  • Global variable: A variable whose scope is "global" to the program, it can be used and updated by any part of the code. Its global scope is typically derived from the variable being declared (created) outside of any function, object, or method

  • If-statement: The common programming structure that implements "conditional statements"

  • Local variable: A variable that can only be seen, used and updated by code within the same scope. Typically this means the variable was declared (created) inside a function; includes function parameter variables.

  • Variable scope: dictates what portions of the code can "see" or use a variable, typically derived from where the variable was first created. (Global v. Local)

  • Concatenate: To link together or join. Typically used when joining together text Strings in programming

    • Ex. "Hello, "+name

  • String: Any sequence of characters between quotation marks

    • ex: "hello", "42", "this is a ---"

  • Conditionals: Statements that only run under certain conditions

  • Selection: A generic term for a type of programming statement (usually an if-statement) that uses a Boolean condition to determine, or select, whether or not to run a certain block of statements.

  • Boolean: A single value of either TRUE or FALSE; created by the mathematician, George Boole

  • Boolean expression: in programming, an expression that evaluates to True or False

Intro to Design mode
  1. Switch between design mode and code mode.

    • Design mode allows you to add UI elements onto the screen and change the position of them. It also allows you to add and move between screens

    • Code mode allows you to add event handlers to control what goes on in the screen.

  2. To add elements onto the screen, just drag the element to the place you want to put it.

    • Once it's on the app screen you can reposition it, resize it and change lots of other properties about it

  3. The Properties tab shows you everything you can change about the look and feel of a UI element

    • This includes things like size, color, shape, position, and text

    • You can also change the id of the element

      • It is context-sensitive, which means that the set of properties you see depends on what you click on in the app.

  4. The element ID is important because it's how you refer to the element in your code.

    • Always make sure to use a meaningful id that is not too general

  5. You can make the text that the user sees on the button text be whatever you like.

  6. Scroll down to see other properties for a UI element that might be "hiding" down below.

Data Types
  • Number: self-explanatory; an integer

    • Ex. 5,8

  • String: characters in quotation marks concatenated together

    • Ex. “5”+” + 7” + “ is equal to”

  • Boolean: true or false

  • Data can be held in variables

Global vs Local