Problem 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

}


Problem 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)
sort(randomNumber)
print("Max Number:")
print(max(numAttempts))
Attempts: [1, 6, 6, 8]
Max Number:
8

Problem 3.

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

Repeat until reach gray square:

If canmoveForward

Move_Forward

else {

if canturnright{

    turnright
}
if canturnleft{
    turnleft
}

} }


Problem 4.

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


Problem 5.

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

  • We can use sequential search
  • Iterate through the list
  • Compare each number until we find 69
  • We can also use binary search
  • Begin from the middle index then continue to the other numbers

Problem 6.

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

Middle index

(1+8)/2=4.5~5

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


Problem 7.

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

["Store”,”Walmart”,”Market”,Target”,”Ralphs”]


Problem 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. Binary is able to search for half the numbers in a data set in one iteration, while sequential search has to go through every possibility.


Problem 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 9, which would take 3 iterations. You would start at 16, the middle index. Then you would do 4+4/2 to get 4, so the next index would be 9.