Do you want BuboFlash to help you learning these things? Or do you want to add or correct something? Click here to log in or create user.



#cs50 #lecture-1

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
11 else
12 quit
  • 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.

  • The last 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.

Words like pick up, open, and look are equivalent to functions in code, like verbs or actions that allow us to do something.

if, 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.

Finally, go back creates loops, or series of steps that happen over and over, until we complete our algorithm.

If you want to change selection, open document below and click on "Move attachment"

Lecture0
ferent shape, with time to solve growing more and more slowly as the size of the problem increases, since we are dividing the problem in half with each step. So an increase from 1000 to 2000 pages only requires one more step to solve. <span>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 11 else 12 quit 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. The last 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. Words like pick up , open , and look are equivalent to functions in code, like verbs or actions that allow us to do something. if , 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. Finally, go back creates loops, or series of steps that happen over and over, until we complete our algorithm. Introductions CS50 students are supported by a team of over 100 staff members, a few of whom will say hello. Doug Lloyd, who took CS50 12 years ago with no exp


Summary

statusnot read reprioritisations
last reprioritisation on suggested re-reading day
started reading on finished reading on

Details



Discussion

Do you want to join discussion? Click here to log in or create user.