We also need to formalize the steps we are using to solve this problem. We can write something like the following:
0 pick up phone book 1 open to middle of phone book 2 look at names 3 if Smith is among names 4 call Mike 5 else if Smith is earlier in book 6 open to middle of left half of book 7 go back to step 2 8 else if "Smith" is later in book 9 open to middle of right half of book
10 go back to step 2
We start counting at 0 because that’s the default lowest value, with all the bits off.
In step 3, we have the word
if, which is a fork in the road, where the next step may not be taken, so we indent it to visually separate it from the lines that are always followed.
else, in step 11, happens if we’re on the last page and Mike isn’t in the phone book, since we can no longer divide it.
These steps are pseudocode, English-like syntax that is similar in precision to code.
look are equivalent to functions in code, like verbs or actions that allow us to do something.
else if, and
else are the keywords which represent forks in the road, or decisions based on answers to certain questions. These questions are called Boolean expressions, which have an answer of either true or false. For example,
Smith among names is a question, as is
Smith is earlier in book and
Smith is later in book.
Notice too, that with one bit, we can represent true, with on, or 1, and false, with off, or 0.
go back creates loops, or series of steps that happen over and over, until we complete our algorithm.