Notes

3.9 Video 1

Dice game take aways

  • small mistakes or changes can alter code greatly
  • there is more than one way to achieve a result

Conditional vs Boolean

How could this conditional scenario be replaced with a boolean scenario?

IF (isHoliday) { school⟵false } ELSE { IF(isWeekday) { school⟵true } ELSE { school⟵false } }

Can be written as: school⟵((NOT (isHoliday)) AND (isWeekday))

Comparing Algorithms

  • As long as both algorithms work despite looking differently they are the same.

3.9 Video 2

Vocab

  • Iteration: Repeating steps, or instructions over and over again. ( this could be also often called a loop )
  • Selection: is a decision or question. At some point in an algorithm there may need to be a question because the algorithm has reached a step where one or more options are available.

Flowchart + Psuedo code

A flowchart can also be written in Psuedo code. Same thing with how algorithms can be written differently but have the same result.

3.9 Video 3

Vocab

  • Algorithm: A process or set of rules to be followed in calculations or other problem solving operations, especially by a computer.

3.11 Notes

  • follow an order by going down a order to find the number you’re looking for
  • you have to compare each number you’re searching for
  • takes the lowset index and highest index to find the middle value and starts there
  • must order from ascending or descending order
  • can also be applied to strings as long as their ordered preferably alphabetically

Hacks

1.

Boolean Statement: stayInside⟵((isCold) OR (isRaining))

Conditional:

  • If (isCold) {
    • stayinside ⟵ true
  • }
  • ELSE
  • {
    • If (isRaining) {
    • stayinside ⟵ true
    • }
  • }

2.

3.

  • REPEAT UNTIL GoalReached

  • If CAN_MOVE FORWARD
    • MOVE_FORWARD
  • ELSE
    • IF CAN_MOVE RIGHT
      • ROTATE_RIGHT
      • MOVE_FORWARD

4.

5.

To find 69 in the list above, you would start with the middle index which is 4.5 since 1+8=9 and 9/2 = 4.5. From there, I rounded up to the 5th index and chose to start with 6 as my middle index. Then I have to find my two next middle indexes which is where I add 6 and 8 together to get 14 and divide that in a half to get 7. My other half middle index is 4+1= 5 and divided in half is 2.5 which I round up to 3. Since I still have not found 69 I keep going n pick my next middle indexes. Because the only two other numbers in between index 5-8 are index 6 and 8 I can find 69.

6.

7.

[“Market”, “Ralphs”, “store”, “Target”, “Walmart”]

Sorted alphabetically to aid binary search.

8.

Binary search is more efficient than sequential search because sequential search is time consuming as it takes up more time to run through every item in the list, where as Binary starts in the middle and splits time in half by starting with a middle index and checking two by two on the way down.

9.

The number I am finding is 16 because it’s the first one that will be the output of binary search and it would take only one check.