1

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

IF (isCold or isRaining) {
    stayInside  True
}
ELSE {
    stayInside  False
}

2

Create an algorithm that uses selection and/or iteration that will represent one player’s complete turn.

  • 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.
  • After they have had 4 chances, their score is the greatest number they received from the random number generator, and their turn is over.
import random
numAttempts = []

i = 1 
while i <= 4:
    numAttempts.append(random.randint(1,10))
    i = i +1 
    
print("Attempts:", numAttempts)
print ("----------------------------------")
print("Maximum number from player:")
print(max(numAttempts))
Attempts: [5, 10, 7, 2]
----------------------------------
Maximum number from player
10

3.

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

for x in range(0, 3):
    move forward 
turn right 
for x in range(0, 5):
    move forward 
turn right
for x in range(0, 2):
    move forward 
# this wouldn't be the fastest way for the robot to get to the other side but
# it is much more efficient coding wise
{
if CANMOVEFORWARD{
    moveForwards
}
else{
    if CANTURNRIGHT{
        turnright
    }
    if CANTURNLEFT{
        turnleft
    }
}
}

4

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

5

Explain thoroughly how to find the number 69 in the list above (use key words)

  • Using sequential search we would iterate through the list and compare each number until the number 69 matches, this would take 7 iterations so a binary search would be a faster way to do this
  • using binary search, you would start from the middle index, then you continue to the next numbers by looking at the first and last index, and dividing by two. You keep following through until you get 69.

6

Make a diagram explaining how you found the list (not tree, include equation)

7

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

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

8

Explain why Binary Search is more efficient than Sequential Search

  • Binary search is more efficient because it moves exponentially while sequential search moves through the list one by one.In big data sets, binary search would rule out half the numbers in one iterations, while sequential search has to go through every possibility. Therefore, binary search is far faster and efficient.

9

[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 searching for the number 11, which would take two iterations. You would start at 16, the middle index. Then you would do 3+5/2 to get 4, so the next middle index would be 11, which is the number we want to find.