Vocab

  • Binary:
    • Bits
      • Bits are single pieces of information which can either have a 0 or a 1. They are the building block of all code.
    • Bytes
      • A single byte is 8 bits. Megabytes, Gigabytes, etc are all multiples of bytes and they represent memory or storage
    • Hexedecimal
      • base 16 counting. Binary is a base 2 system
    • Unsigned Integer
      • An unsigned integer is a basic number value in bits. It does not include a negative or positive and therefore is non-negative
    • Signed Integer
      • An integer with a negative or positive
    • Floating Point
      • A way of approximately representing decimal values
    • Boolean
      • Data type with a true/false value, can be represented with 1s and 0s
    • ASCII
      • A Character encoding standard, transfers binary to chars
    • Unicode
      • Another character encoding standard, builds on ASCII
    • RGB
      • Color codes are represented in Hexidecimal which describe the red green and blue values to build a color EX: #FF0000, rgb(255, 0, 0)
  • Algorithm Terms:

    • Variables: An abstraction inside a program that holds a specific value or meaning defined by the programmer.
    • Data Types:

      • Integer- highScore (involves math, save as integer or numbers)
      • String- firstName (name is text, so it is a string)
      • Boolean- isSunny (2 options, true or false)
      • String- phoneNumber (no math, just numbers)
    • Arithmetic Operators:

      • Plus indicated addition (a + b)
      • Minus indicates subtractions (a - b)
      • Asterisk indicated multiplication (a * b)
      • Slash indicated division (a / b)
    • Managing Complexity:
      • Lists: Allows you to complete a process for each value in the list, or store multiple values to one variable.
      • 2D Lists: Array within an array. You can pull single arrays through using index and variable commands.
      • Dictionaries: Allows the storage or data keys and values (assigning a certain piece of data to fit the category it is assigned)
      • Class: A particular data structure.
      • Algorithms: An algorithm is a finite set of instructions that accomplish a specific task, us as humans, do algorithms on a daily basis.
      • Sequence: A specific order a process is completed, which impacts the output.
      • Selection: Programmer decides between 2 different functions
      • Iteration: Repetition of a process
      • For loop: repeats a section of code a set number of times
      • While loop: repearts a section of code an unknown number of times, until the code is told to break
      • Expressions: A piece of syntax in coding
    • Characters:
      • Strings : A variable data type which consists of a combination of letters, numbers, and other special characters (ex: @#$%^&*). They are seen inside quotation marks, and operators cannot affect any numbers in the string.
        • Ex: stringVar = “Hello World!”
        • “Hello World!” is a string.
      • Length: The number of elements in a list. Here’s an example in Python:
        • numList = [1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 8 , 7 , 6 , 5 , 4 , 3 , 2 , 1]
      • Concatenation: the act of joining two strings into a single string. Often, these strings are printed to an output terminal/console. Here’s an example in pseudocode:
        • concat(“tri”, “llion”)
        • This concatenates the strings “tri” and “llion”, making a new string “trillion”.
      • Upper, Lower, Traversing Strings
        • The first two (upper and lower) seem to be referring to Python methods. They are quite simple. I think it would be easiest to explain with a demonstration:
        • String = “WhYaReWeDoInGtHiS”
        • print(string)
        • print(string.upper())
        • print(string.lower())
        • Output:
        • WhYaReWeDoInGtHiS
        • WHYAREWEDOINGTHIS
        • whyarewedoingthis

Variables, Assignments, Data Abstraction

Variables

  • Abstraction insde a program that can hold a value
  • Organizes data with a name
  • Consist of name, value, type
  • Understanding of code is through name of variables
  • Types of data:
    • Interger, String, Boolean
    • List can also be stored in variables
      • Print/retreive specific values
      • easily able to add and remove values

Assignments

  • Assignment operator allows program to change value represented by variable
    • =, +=, -=, *=, /=, **=

Data Abstraction

  • Method used in coding to usefully represent data
  • Variables and list are primary tools
  • Provides seperation btw abstract properties of a data type and concrete details of its representation

Algorithms

  • Sequencing
    • Algorithms do tasks in the order of specification.
  • Selection
    • Helps choose two different outcomes based off a decision.
  • Iteration
    • If a condition is true, then the code can repeat.
  • Flowcharts
    • Use shapes and arrows to represent the steps of an algorithm.
  • Pseudocode
    • A blend of human language and coding format.

Arithmetic Operation

  • Arithmetic operations exist in most programming languages.
  • subtraction (-)
  • addition (+)
  • multiplication (*)
  • division (/)
  • Getting the remainder (%)
  • ORDER OF OPERATIONS is crucial
    • reassigning variables using operations on other variables can get confusing
  • PAY ATTENTION TO SEQUENCING SO OPERATIONS OF VARIABLES DONT GET MESSED UP
  • Track varaibles (common question in AP Exam)

String

  • A string is a collection of characters. What is a character as character can be anything from numbers, letters, spaces, special symbols, etc.
  • len () : to find the length of a string
  • lower () : to convert to lowercase
  • concat (): in pseudocode and varys from language to language can be used to combine to strings

Lists and Iteration

Lists

  • Sequence of variables
    • Used to store multiple items in a variable
    • ordered and flexibe
  • Tuple: collection thats ordered, unchangeable, allows duplicates
  • Set: Unordered, unchangeable, doesn't allow duplicates
  • Dictionary: ordered, changeable, doesn't allow duplicates
  • Index: refrences an element in a list that is in order
  • Elements: values in the list that are assigned to an index
  • Methods:
    • append() adds elements
    • index() returns the index of the first element with specificed value
    • inset() adds element at given position
    • remove() removes the first item with the specified value
    • reverse() reverse list order
    • sort() sorts the list
    • count() returns amount of elements with specified value
    • copy() returns a copy of the list
    • clear() removes elements from list

Iteration

  • repetition of a process applied to the result or taken frmo previous statement
    • for loops
    • while loops
  • 2 types of iteration: indefinite and definite
    • definite: clarifies how many times the loop is going to run
    • indefinite: how many times its going be ran based on conditions
  • When object is iterable it can be used in an interation
  • Iter() returns an interator
  • Strings, list, dictionaries, sets, and tuples are iterable objects
  • Break: stops the loop

2D Iteration

  • Lists of lists
  • Read in 2 dimensions (list on top of list

Algorithms and Conditionals vs Booleans and Binary Search/Flowcharts

Algorithms

  • Process or set of rules to be followed through code
    • Set limitations
  • Algorithms can be written in different ways and still accomplish the same tasks
  • Algorithms that appear similar can yield different side effects or results.
  • Some conditional statements can be written as the same as Boolean expressions (VICE VERSA)
  • Different algorithms can be developed or use to solve the same problem. ## Conditional vs Booleans
  • Boolean expression when an expression outputs true or false
  • Booleans can only hold true or false ## Flowcharts
  • Help you visualize functonality of an algorithm
  • Good way to double check whether an algorithm is acheiving its purpose ## Binary Search
  • Search algorithm that finds position of target value within a sorted array
    • Algorithm for iteratin gto find a value inside a data set
  • Starts in middle of data set and eliminates half the data
  • COLLEGE BOARD INDEX STARTS AT 1 NOT 0 ## Libraries
  • A library is a collection of precompiled codes that can be used later on in a program for some specific well-defined operations.
  • These precompiled codes can be referred to as modules. Each module contains bundles of code that can be used repeatedly in different programs.
  • A library may also contain documentation, configuration data, message templates, classes, and values, etc.
  • Importance:
    • Using Libraries makes Python Programming simpler and convenient for the programmer.
    • One example would be through looping and iteration, as we don’t need to write the same code again and again for different programs.
    • Python libraries play a very vital role in fields of Machine Learning, Data Science, Data Visualization, etc. ## APIS
  • An Application Program Interface, or API, contains specific direction for how the procedures in a library behave and can be used.
  • An API acts as a gateway for the imported procedures from a library to interact with the rest of your code.

Examples

List Example:

colorsList=["pink", "yellow", "green", "blue", "orange"]

print(colorsList)
['pink', 'yellow', 'green', 'blue', 'orange']

Variable type examples (string,integer,boolean):

name = "table1" #string
print(name, type(name))

number = 4 #integer
print(number, type(number))

isAbsent = False
print(isAbsent, type(isAbsent))
table1 <class 'str'>
4 <class 'int'>
False <class 'bool'>

Operators Examples:

num1 = 2 - 1
num2 = 2 + 1
num3 = 2 * 1
num4 = 2 / 1
num5 = 5%2
print(num1)
print(num2)
print(num3)
print(num4)
print(num5)
1
3
2
2.0
1

Algorithm Examples

Algorithms with same code but differnt results

temp = int(input("Select a temperature from 0 to 99 degrees F"))
if (temp >= 90):
    print("It's too hot outside!")
else:
    if (temp >= 65):
        print("Sure I will play outside!")
    else: 
        print("It is too cold outside!")
# Input 54 and then 95, what do you notice?
It's too hot outside!
temp = int(input("Select a temperature from 0 to 99 degrees F"))
if (temp >= 90):
    print("It's too hot outside!")
if (temp >= 65):
    print("Sure I will play outside!")
if (temp < 65):
    print("It is too cold outside!")
    # Input 54 and then Input 95, what do you notice?
It's too hot outside!
Sure I will play outside!

Algorithms that accomplish the same task but differnet code

sum = 1
counter = 3
#iteration
var = 0 
while (var < 4): #while the var is <= 4, it executes those commands, once it exceeds it hits the else command
    sum = sum + counter
    counter = counter + 2
    var = var + 1
    # now go through the whole thing 4 times, this is an iteration, a vital part of algorithms.
else:
    print(sum)
sum = 0
counter = 9
#iteration
while (counter >= 1): 
    sum = sum + counter
    counter = counter - 2
print(sum)

Building an Algorithm Steps:

print("choose value for x")

varx=int(input("Enter any positive Integer"))

if (varx %2 == 0):
     varx == varx/2       # Change print to the function

else:
    varx == varx * 3 + 1      # Change print to the function

print(varx)
print("choose value for x")

varx=int(input("Enter any positive Integer"))

while varx != 1:

    if (varx %2 == 0):
        varx = varx/2       # Change print to the function

    else:
        varx = varx * 3 + 1      # Change print to the function

print(varx)
print("choose value for x")

varx=int(input("Enter any positive Integer"))

print(varx)
while varx != 1:

    if (varx %2 == 0):
        varx = varx/2       
        print(varx)               # add Display
    else:
        varx = varx * 3 + 1      
        print(varx)               # add Display
print(varx)                       # Final # Should be 1 every time

Binary Search Example:

def BinarySearch(array, x, low, high):

    # Repeat until the pointers low and high meet each other 
    while low <= high:

        mid = low + (high - low)//2 # find the middle (taking the higest index number plus the lowest and divided by two)

        if array[mid] == x: # if desired number is the middle is found return desired number (middle number) 
            return mid

        elif array[mid] < x: 
            low = mid + 1

        else:
            high = mid - 1

    return -1


array = [3, 4, 5, 6, 7, 8, 9]
x = 4

result = BinarySearch(array, x, 0, len(array)-1)

if result != -1:
    print("Element is present at index " + str(result))
else:
    print("Not found")
Element is present at index 1