3.1 Variables and Assignments

  • Variables are specific things that stores a value
  • Values can be individual datas or a list/collection that contains many data values
  • Types of data include ints, Booleans, lists, and strings
    • Floats work just like ints, but floats have decimals
  • Assignments is done with the = sign
    • Lists are assigned withcan have values added to them with the append function
    • Dictionaries are initialized with {} and : signs
    • variables can also be assigned
  • Expressions can be used to change a number +,-,*,/,//,% are some of the examples

3.2 Data Abstraction

  • Connects the abstract data with concrete details of its representation
  • Manage Complexity by refering to a variable without assigning it to a name
    • Lists can treat many variables by treating it like a single variable.
  • Data abstraction makes it easier to maintain code
  • Collegeboard lists starts at 1, instead of 0 like most programming languages
  • The split function can be used to split a string into a list

3.3 Expressions

  • Symbols that do something
    • + is addition,
    • - is subtraction,
    • * is multiplication
    • / is division
    • ** is exponent
    • % is modulation
  • They operates on values to produce a result
  • Algorithm is a set of procedures that does something

3.4 Strings

  • Functions like a list of chars, with indexes at each char of itself.
  • Concatenaction is the addition of a string to another, with the + expression
  • Length is the number of chars in a string
  • A substring is a part of a string
  • Psuedocode is a procedure that is not written in actual code, but is easiliy understandable

3.5 Boolean Expressions

  • Boolean Expression reads off operands at its two sides and returns a boolean result
    • Consists of Relational and Logical Operators
  • Relational Operators consists of ==, !=, <, >, <=, >=
  • Logical Operators' operands is only booleans and consists of not, and, or
  • In evaluation, Relational Operator goes first, then not, and, or, in that order

3.6-7 Conditionals and Nested Conditionals

  • Conditionals decides the flow of the algorithm depending on a boolean
  • If the boolean is true, it goes to the if clause, else, it goes to the else clause
  • Conditionals are good to construct algorithms
  • Nested Conditionals are if-else clauses in side a if-else clause and helps algorithms further

3.8 Iteration

  • Iteration is the repetition of a particular set of algorithm
    • Conditional Iteration is iterations that only stops when a condition is met, often using if statements
  • Iteration is often done using loops
    • Also often uses lists or dictionaries
  • Nested loops is useful for iterating inside a iteration

3.9 Algorithm

  • Algorithm is a set of procedure that can be followed to solve a problem
  • A problem can have many algorithms that solves it
  • When looking at a program, it is important to understand the algorithm used to control it
    • An algorithm can have flow control controlled by if-else statements
  • Understanding what parameters should go in is necessary

3.10 Lists

  • Lists are a number of items that is refered to by an index
    • In most languages, the index start at 0 (but it starts at 1 for collegeboard)
  • Lists can be used to store a large amounts of information that would've required a lot of variables to store
  • Methods can be used on lists to modify what the list is made of as well as access specific values

3.11 Searching

  • Searching is a way for the computer to find the location of a value
  • Searching each value in succession is not optimal
  • Having the list being sorted from least to great can enable binary search
    • Binary search is more optimal than searching each one in succession, having log complexity than linear complexity
      • Divide the list in 2 parts at each step, so no need to look over every value

3.12 Procedure

  • Procedure is a named method of code that takes input and returns output
    • Basically same as function
  • Parameter is the values that a procedure takes in
  • Arguments are things specifying the values of parameter

3.13 Developing Procedures

  • Need to know things in order to create a procedure
    • The type, value, and meaning of the input
    • The intended output and how to arrive at the output
  • Modularity is the seperating of parts into functions to simplify things
  • Procedral Abstraction is calling a procedure without actually stating what a
    • Basically the ability to function calls
  • A return statement ends a procedure and returns a value
    • Done with the return keyword in most languages

3.14 Libraries

  • Libraries are preexisting sets of functions that have to be imported to be used
  • In python, libraries are imported with the import keyword
    • math is a python library that has functions that helps with maths, like square roots and trignometry
    • turtle is another library that can draw things on a canvas

3.15 Random

  • Randomness in programming is done with a random number generator, or the RNG gamers often talks about
  • random is the python library for randomness, it has several useful functions to generate random values
    • random.random() generates a random float between 0 and 1
    • random.randint() generates a random int between its two parameters, inclusice
    • random.shuffle() randomizes the order of a list
  • Randomness is often used to simulate real world scenerios that is random
    • Example: a die roll

3.16 Simulation

  • Simulation is a program that simulates a simpler version of a real-world event
  • Can change things without real world concerns, i.e "Let's reduce the population by 1/2"
  • Often simplify things to make simulating easier
    • Can cause bias without meaning to because of accidental exclusion of a variable that changes the outcome in real life
  • RNG often used to create randomness

3.17 Algorithmic Efficiency

  • Problem is a task that may or may not be solvable with an algorithm
    • Decision Problems gives a yes or no answer
    • Organisation Problems seeks to find the best answer
  • Instance is a set of specific inputs of a problem
  • Efficiency is how fast the program can run, or the amount of computing that needs to be done to solve the problem
    • Most of the time we want a program to increase efficiency linearly or less when we have more inputs
  • Heuristic Approach is the approach that sacrafices the optimal solution for more efficiency

3.18 Undecidable Problems

  • Undecidable problems are problems that have no solution
    • Can result from a paradox
    • Can cause a time out of a website due to the internet being stuck in a paradox that is not fixed