S.NO Assignment Assignment Assignment Assignment
Week 1 3.1-3.2 Notes and Hacks 3.3-3.4 Notes and Hacks Group Grades  
Week 2 3.5-3.7 Notes and Hacks 3.8-3.10 Notes and Hacks 3.9-3.11 Notes and Hacks  
Week 3 3.12-3.13 Notes and Hacks - -  
Week 4 - - -  

3.1-3.2

  • (This was my groups presentation)

3.3-3.4

3.3

an Algorithm is a set of instruction that accomplish a task

Sequencing

  • The order of how you do something
  • Like the instructions of a teacher and howo you follow them

Selection

  • Allows the algorithm to make a decision based on if a condition is met
    • Go to the gas station if your tank is empty, dont if its full.

Iteration

  • A loop that does something over and over again until a condition is met

Mathematical Expressions

  • Sequential statements specify how signals are assigned and the process that is executed as a whole.
    • Execute in the order in which they appear

Examples of arithmetic operators:

-Addition: a+b -Subtraction: a-b -Multiplication: a*b -Division: a/b -Modulus: a MOD b (a and b can be string or number)

Modulus operator divides the given numeratior by the denominatior to find the result.

  • The syntax is %.

Strings

  • String concatenation joins two or more strings end to end to make a new string

Examples of strings in pseudocode:

  • len (str)
    • returns the number of character is str
    • len(“hello”) returns 5
  • concat (str1, str2)
    • returns a single string consisting of str1 followed by str 2
    • concat(“hello”,”world”) return ‘hello world’
  • substring (str1, str2, length)
    • returns a substring of consecutive character from str1, starting the character at position ‘start’ and containing ‘length’ character
    • substring (“hello”,”world”, 4,5) returns ‘lo wor’

Sequencing

  • The order of how you do something
  • Like the instructions of a teacher and howo you follow them
  • It was 1-5 on the image

Selection

  • Allows the algorithm to make a decision based on if a condition is met
    • Go to the gas station if your tank is empty, dont if its full.
  • It was #3 on the image

Iteration

  • A loop that does something over and over again until a condition is met
  • Was #4 on the image

3.5 - 3.7

What is Boolean

  • Denotating system of algorithmic notation in computing or electronics
    • Boolean examples are either true or false
      • Example: Sky is blue - True

Relational operators

  • The mathmatical relationship between two variables
  • Determines an output on whether or not the statement is true
  • a=b, a>b, etc.

Logical Operators

  • NOT displays the opposite of whatever the data is
    • usually used for true/false

  • AND is used to evaluate 2 conditoons together to determine of both conditions are met
    • Example: if grade is above 70 and grade is below 100, you passed the quiz.

  • OR, if one of the conditions are met, the function works.

Conditionals

  • Conditionals allow for the expression of algorithms that utilize selection without a programming language.
  • Writing conditional statements is key to computer science.
  • Determine the result of conditional statements

Key Terms

  • Selection is The specific block of code that will execute depending on the algorithm condition returning true or false.
  • Algorithm is “A finite set of instructions that accomplish a specific task.”
  • Conditional Statement / If-Statement is a statement that affects the sequence of control by executing certain statements depending on the value of a boolean.

  • Conditional statements (“if” statements) affect the sequential flow of control by executing different statements based on the value of a Boolean expression. The exam reference sheet provides:

  • In which the code in block of statements is executed if the Boolean expression condition evaluates to true; no action is taken if condition evaluates to false

Nested Conditionals

  • Conditional statments within a conditional statement
    • example: an else if inside of another else-if\
    • Can be used for a varying amount of “else if statements.” The first if statement can represent if two coditions are true. The first else if can represent if only one or the other is true. The last else if represents if neither of the conditions are true.
    • Can have three different conditions

3.8 - 3.10

Iteration

  • Iteration is a repeating part of an algorithm that repeats a specfied number of times until a condition is met
  • Iteration statemtns change the sequential flow of control by repeating a set of statements zero or more times, until a stopping condition is met

Example:

  • Trying to find a lost item
    • Determine what the item is
    • Ask every family member/friend who would see it
      • Stop condition: If you find it go to step 5
    • make a full sweep of everywhere you have
      • Stop Condition: If you find it go to step 5
    • Repeat steps 2 and 3 until the item is found
    • If never find it: Go Back to your room and cry
    • If you find item: enjoy the item
  • Example in code

Result of Iteration Statements

  • When using a range function, the last number in the input is not included in the output.
    • Starting value: The number that the range function will start with
    • Incrementing: The number in which the range increments by
    • Ending value: The final number of the range.

Loops

  • While loops use a condition then print something based on a condition.
    • This example prints all even numbers less than 10.

  • the percent sign means modulus so meaning if there is a remaninder when we dvide. So if number divided by 2 has no remainder then it will print number.
  • Then after that it will add 1 to the number and repeat the process untill it reaches 10.

3.10

Lists

  • the process of visiting each element in a list in a sequential order.
    • Complete Traversal: All elements in a list are assessed - Partial Traversal: Only a given portion of elements are assessed
    • Iterative Traversal: When loops are used to iterate through a list and to access each single element at a time.
  • Traversing allows you to access or search for certain elements

College Board Lists

  • insert( ) allows a value to be inserted into a list at index i
  • append( ) allows a value to be added at the end of a list
  • remove( ) allows an element at index i to be deleted from a list
  • length( ) returns the number of elements currently in a specific list

Here is an example question

  • The answers would be B and D, because they value the responsies rather than the animals

  • The loop above allows the coder to access each item within the list

3.9 - 3.11

Algorithms Review

  • Three components of an algorithm are:
    • Selection
    • Sequence
    • Iteration
  • Different algorithms can be used to achieve the same result
  • Algorithms that look the same can also have different results

  • As you can see these are slightly different codes, but since I inputed the same grade (93 NOT 90 lol) for both, I recivied the same result.

  • Its kind of like debugging how very small changes in similar algorithms can make durastic differences.

  • Can help display to future self or other people what each part of the code does.

Nested Conditional statements

  • This nested conditional displays an algorithm that tells you whether you should go to school or not depending on the day of the week.

Developing Algorithms

  • Outline the process of the code first so you ensure that it is sequenced correctly
    • Its good to make a flowchart to visualize all the steps of the process
    • Makes the coding process more effective.
    • Start off with doing it in natural lingo, rather than a flow chart.
  • Algorithms with iteration repeat a function until a goal is reached
    • To more easily represent an algorithm without showing all the repeated steps, we can use iteration
  • Algorithms with selection only go through certain functions if certain things are true or false

Example

The parking rate for a garage is as follows:
Less than one hour: Free
1-2 hours: $5
2-3 hours: $8
3-4 hours: $10
4+ hours: $12

  1. Start
  2. Input number of hours parked
  3. If hours is less than 1, cost is free
  4. If hours is between 1 and 2, cost is $5
  5. If hours is between 2 and 3, cost is $8
  6. If hours is between 3 and 4, cost is $10
  7. If hours is more than 4, cost is $12
  8. Display cost and goodbye
  9. Finish

  • I inputted “4 hours parked” and the algorithm determined that my parking would cost $12.

Using preexisting algorithms

  • Knowing existing algorithms can help construct new ones
  • simple existing algorithms can include
    • determining min or max of two or more numbers
    • computing the sum or average
    • identifying if an integer is even or odd
  • Using existing correct algorithms can help as building blocks to reduce development time, testing, and identification of errors
    • You don’t need to code everything from the ground up.
  • Modifying the preexisting code, you can develop on it and make a better code.

Steps:

  • first put the numbers in order
    • ascending
    • descending
  • find the middle number first
    • this is found by taking the highest index number plus the lowest index number and divide by 2
    • the numbers on the right will be greater and the numbers on the left will be smaller
    • this can be represented with a binary tree
      • middle number with the smaller number branched off on the left and bigger numbers branched off on the right
  • these lists are not always numbers
    • lists can be made with strings
    • ex. [“apple”, “banana”, “cherry”, “peach”, “watermelon”]
    • alphabetical order
      • a-z