Section 9-11 Hacks
All tangibles and group hacks
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
#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
- }
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
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.