Big Idea 3: Algorithms And Programming (30-35%)
3.1 Variables and Assignments
● Variable : abstractions inside a program that can hold a value
○ Can change in value
○ each variable has associated data storage that represents one value at a time,
but
the value can be a list
● Variable name: concise, represents the variables
● Value : list or other collection that in turn contains multiple values
(anything!)
○ Welcome ← “hello world”
○ Storing “hello world” in “welcome” variable
● Type of data stored:
○ Integer: scores (needed to do math)
○ text/string: name, phone number
○ Boolean: question (true or false)
3.2 Data Abstraction
Represents a list or string using a variable
● Strings : ordered sequence of characters (letters, numbers, all special
characters ($))
● elements : individual value in a list that is assigned a unique index
● Lists : ordered sequence of elements (each element is a variable)
● List index: Each individual part of the string is referenced by an index
- An index is a method for referencing the elements in a list or string using
natural numbers.
● Data abstraction: provides a separation between the abstract properties of a
data type and
the concrete details of its representation
3.3 Mathematical Expressions
● Algorithm: a finite set of instructions that accomplish a specific task
(recipe. following
specific steps in order to make something specific)
● 3 components
1. Sequencing : application of each step of an algorithm in the order in which
the
code statements are given (steps. 1st, 2nd, 3rd)
a. Code statements : expresses an action to be carried out
2. Selection (two different outcomes: yes or no, true and false)
3. Iteration (repeating when true/false, break when true/false) - loop
● expression: consists of value, variable, operator, procedure call that
returns a value
(produce a single value when evaluated)
SEQUENCIAL STATEMENTS execute in the order they appear in the code segment
3.4 strings
● concatenation: joins together two or more strings end to end to make a new
string
● slicing: part of an existing string (provides range)
○ substring(“APCSPrinciples”, 3, 6) —> returns “CSPrin”
● len(str): returns a number of characters in a string
○ len(“happy”) → returns 5
3.5 boolean expressions
● Boolean value : either true or false (yes or no questions)
● Relational operators: =, ≠, >, <, ≥, and ≤.
● Logical operators: NOT, AND, OR
○ NOT Operator : reversing the initial value when added next to the result
(FLIP)
○ AND Operator: evaluating two conditions (if they are BOTH true)
○ OR Operator: one of those conditions to be true
● True AND False = False
● True OR False = True
3.6 Conditionals
● Selection: determines which part of an algorithm are executed based on a
condition being
true or false
● Conditional statements: execute different statements based on the value of a
boolean
expression
○ Condition must be met in order for certain parts of the program to be executed
○ If statements: affects the sequential flow of control by executing different
statements based on the value of a boolean expression
○ Else statement: if condition wasn’t met
3.7 Nested Conditionals
● Nested conditionals: statements consist of conditional statements within
conditional
statements (statement NESTED in another statement)
3.8 Iteration
● Iteration : repeating portion of an algorithm (specified number of times or
until given
condition is met)
○ Changes sequential flow of control by repeating
● Break when needed to stop
● “repeat n times” = statement executed n times
● “repeat until (condition)” = repeat until boolean expression condition
evaluates to true