Unit 3 Section 9 and 11 Hacks
- Write this Boolean statement in the form of a conditional (if/else) statement: stayInside⟵((isCold) OR (isRaining))
- 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
numTurn = 0
score = []
length = len(score)
while numTurn < 4:
numTurn = numTurn + 1
score.append(random.randint(1,10))
score.sort()
print(score)
print(score[len(score) - 1])
- Create an algorithm that will allow the arrow to reach the gray square:
- Make a binary search tree of different the list [1,2,3,4,6,9,11,69]
- Explain thorughly how to find the number 69 in the list above (use key words)
Since binary search is being used, to find 69 in the list above one must first get the middle index (4.5) and round it up to 5, the 5th element in the list is 6. Next you continue doing this until you get to 69. The middle index of the middle index would give the integer value of 11 and the next value you would get is 69
- Make a diagram explaining how you found the list (not tree, include equation)
- Put this list of strings in a order that can be used for binary search [“store”,”Market”,”Walmart”,Target”,”Ralphs”]
You could put them in alphabetical order such as ["Market”, ”Ralphs”, “store”, "Target”, ”Walmart”] since that would allow for the correct comparison of the ASCII characters.
- Explain why Binary Search is more efficient than Sequential Search
Binary Search is more efficient than Sequential Search because it finds the value in an organized way (by continuously dividing the data in half), unlike sequential search which finds values using unsorted arrays. Not to mention, by dividing the data in half binary searches reduce the data more quickly since it removes half of the values.
- [64,36,16,11,9] Explain which number you are finding, how many check it would take, and make a binary search tree.
To find the number 9 you would need to check 2 times. When you get the middle index the first time you get 16 since (1+5)/2 = 3 and 16 has the position of 3 and to get 9 you would do (1+3)/2 which gives the index position of 2 which is held by 9.