Question 1

# stayInside to be true, stayInside should be true in this case
isCold = True
isRaining = False
stayInside = True

if isCold == True or isRaining == True:
    stayInside = True
else:
    stayInside = False

print(stayInside) #stayInside is true because isCold is true
True

Question 2

import random
number = 0
greatest = 0

print("Randomly Generated Numbers:")

for i in range(4):
    number = random.randint(1,10)
    print(number)
    if number > greatest:
        greatest = number

print("Player's Score:")
print(greatest)
Randomly Generated Numbers:
9
4
10
8
Player's Score:
10

Question 3

while ArrowNotReachedGraySquare:
    if CANMOVEFORWARD:
        MOVEFORWARD
    else:
        TURNRIGHT

Question 5

Since this list is already ordered from least to greatest, we can skip this step. To find the number 69 in the list in question 4, we would first start by finding the middle element. Since there are an even number of elements in this list, there would be no middle element, so we would use the next element from the middle of the list which in this case would be 6. Since 6 is less than 69, we know that 69 is in the second half of the list with all the numbers greater than 6. Since the middle element of this half is 11 and is less than 69, we know that the number 69 is in the part of the list after the element 11. Since there is only one element in this part of the list, we know that this element is 69 and we have found the desired value 69.

Question 6

Diagram

Question 7

Ordered List: [“store”,”Market”,”Walmart”,Target”,”Ralphs”]

Arranging them in alphabetical order was the best way I could think of to get the list ready for binary search. I first thought of ordering them by length of each string, but then I realized this wouldn't work because some of the strings have the same length.

Question 8

Binary search is more efficient than sequential search because binary search removes half the elements every time which is very effective in pinpointing exactly where the desired element is. Sequential is usually less efficient because if the desired element is towards the end of the list or the list is very long, all the previous elements would have to be checked before reaching the desired element. Therefore, sequential search usually takes more checks to reach the desired value than binary search.

Question 9

Binary Search Tree

If we are searching for the value 36, this will take 2 checks because the first middle index will be found to be 3 because (1+5)/2 = 3. Next the second middle index will be found to be 2 because (1+3)/2 = 2. Since index 2 is the value 36, 36 will be found on the second check.