algorithms sorting


For loop




For example, on the Unit 2 Lab 1 page, Developing a Number Guessing Game with Script Variables , you may choose to explore the concept of a binary search algorithm and to develop an algorithm offline before even opening Snap!. Some teachers have used this approach:

In both of the in-person Number Guessing Game and the Guess My Word games, be animated about the halving process after each clue.
  • First, play a round or two of the Number Guessing Game in small groups or as a class.
  • Then, play a round of 'Guess My Word.' One person selects a (perhaps random) word from a dictionary, and the other person tries to find that word in the dictionary by selecting a word about halfway through the possibilities left and asking if the chosen word is before or after.
  • Then, have a class discussion:Then introduce the idea of writing out an algorithm in regular words (e.g. "prompt the user to pick a number within the range"). Provide chart paper to each group if available.
    • How were we making our guesses?
    • What did we do with the information received (such as "no, the number I'm thinking of is lower", or "no, my word comes after that")?
    Emphasize how the previous guess becomes the new upper bound or lower bound for the new range of possibilities.
  • Encourage students to record the bounds of the range and the number guessed on paper in a new row of a table to help keep track of their algorithm-testing process and to communicate their progress with their group-mates.
  • Now ask students to write instructions for the computer. Their syntax will likely mimic the programming language(s) with which they are most familiar (e.g. Snap!), but they should not be held to this as a constraint.
  • As the very last step, they can code the algorithm in Snap!. If all goes well, the time spent programming in Snap! will be significantly less than the time spent building the algorithm offline as the majority of the debugging will already have been done on paper.


Let’s say I am picking a random number between 1 and 1,000,000

224,031 works

Given only the hints of higher or lower I would begin guessing at


You have just eliminated half of the options. There were 1,000,000 options but now there are only 500,000 options after 1 guess. This slicing continues:

middle of 125,000 and 250,000 is the lower boundary (125,000) + half the distance between the two numbers (62,500)
sooooo 187,500?

Note that regardless of answer the next amount leaves only 31250 options. This is down from 1,000,000 to 31,250, a difference of 968,750. 96.875% bad options eliminated in 4 guesses.

not 224,031 yet … higher

( (upperbound) 250,000 - (lower bound) 224,031 )/ 2 = 12984.5 difference of numbers cut in half
224,031 (lower bound) + 12984.5 (half difference) = 237015.5
lets round for convenience to 237016

227277? in 8 guesses we only have 9739 options left

Well I kept doing this by hand but recognized… I got into coding to make the algorithms do the work for me so I made the following:

Link to number guessing javascript

Now… let me instead copy paste in the results that gets spit out of my script (I love being constructively lazy):

The target number is 481025
Guess #1: 500000?
Guess #2: 250000?
Guess #3: 375000?
Guess #4: 437500?
Guess #5: 468750?
Guess #6: 484375?
Guess #7: 476562?
Guess #8: 480468?
Guess #9: 482421?
Guess #10: 481444?
Guess #11: 480956?
Guess #12: 481200?
Guess #13: 481078?
Guess #14: 481017?
Guess #15: 481047?
Guess #16: 481032?
Guess #17: 481024?
Guess #18: 481028?
Guess #19: 481026?
Guess #20: 481025?
Yes! the secret number was 481025
the answer was found in 20 guesses!
=> ‘EUREKA!!!’

the maximum amount of times it needs to guess is 20. By cutting the number of options in half each step you see the following:

500000 options left after 1 guesses
250000 options left after 2 guesses
125000 options left after 3 guesses
62500 options left after 4 guesses
31250 options left after 5 guesses
15625 options left after 6 guesses
7812 options left after 7 guesses
3906 options left after 8 guesses
1953 options left after 9 guesses
976 options left after 10 guesses
488 options left after 11 guesses
244 options left after 12 guesses
122 options left after 13 guesses
61 options left after 14 guesses
30 options left after 15 guesses
15 options left after 16 guesses
7 options left after 17 guesses
3 options left after 18 guesses
1 options left after 19 guesses
20th answer is the winner in the longest possible path to a solution

Another visualization of it is from the following site:


5 Gifs to Understand Binary Search Trees


Boolean Logic5


More Boolean Logic4


Also, here’s a Google Doodle for G.B.: Birthday Boole4

A good bit-by-bit overview video series:

Little dryer, but the first video does start from the very beginning and has a bit more of the ‘why’:

WarmUpWorksheet-solution.docx11 (877.4 KB)
WarmUpWorksheet.docx15 (868.9 KB)

CompArt 20Slideshow(LoopsConditional)