Notes

  • Sequential search is not as good as its time consuming and leaves you without use.
  • Small changes/mistakes can have a big impact on the result
  • There is often more than one way to achieve the same result
  • Algorithms can be created from an idea, by combining existing algorithms, or by modifying existing algorithms.

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.
  • Algorithm: A process or set of rules to be followed in calculations or other problem solving operations, especially by a computer.
  • Condtiional: a statement that goes if or else supporting two outcomes
  • procedure; a segment of code that provides an output or serves a purpose

1 Write this Boolean statement in the form of a conditional (if/else) statement: stayInside⟵((isCold) OR (isRaining))

{ if(isRaining){ day --> "cold" } if(isCold){ day --> "cold" } }

#During a turn, each player gets 4 attempts/chances to get the greatest number possible.

#During each attempt, the player will use a random number generator to select a random number from 1 to 10.

import random
attempts = []

i = 1 
while i <= 4:
    attempts.append(random.randint(1,10))
    i = i + 1
    
print(attempts)
print("Maximum:", max(attempts))

# This works due to the fact if i=1 and you have 4 atemps you role between the number 1-10 leaving you to add to i per role 
[7, 5, 1, 2]
Maximum: 7

3

Create an algorithm that will allow the arrow to reach the gray square:

  • {
  • if CANMOVEFORWARD{ moveForwards
  • }
  • else{ if CANTURNRIGHT{
      turnright
    
    } if CANTURNLEFT{
      turnleft
    
    • }
  • Explanation: This shows how the robot wil get down to the grey square as it moves forward rigth and left.
  • }

4 Make a binary search tree of different the list [1,2,3,4,6,9,11,69]

questions 4-6

Put this list of strings in a order that can be used for binary search [“store”,”Market”,”Walmart”,Target”,”Ralphs”]

  • To do this you put the list in alphabetical order which makes it [Market ralphs store target walmart]
  • This is correct due to setting everything up in the alphabet leaving it to be in this order

Binary search is better than sequencial search as it is a more efficient way to find items within a list rather than setting up everything side by side.

8. [64,36,16,11,9] Explain which number you are finding, how many check it would take, and make a binary search tree

  • I am finding 36 first I find the middle which is (1+5/2) this would give me the middle and then I would do 1+3/2 which would get me to the number 36 that means. This makes sense becuase binary search is the way of finding the middle of each list and dividing that to make sure you can find a specific number in the list. However if you were to use sequencial search than it would mean you would have to align everything together to find 36 which would take longer and be more inconvienet.

What I learned and What I struggled On

  • I understood the conditionals and how if else statements worked
  • I understood the way of algorithms ### What I struggled on
  • On the 4th question I struggled as I dont know if my numbeers are correct as I may have divided wrong not giving me the number