CS30 - Spring 2015 - Class 24

Lecture notes

  • admin
       - assignment 10
          - use debug mode if your program is freezing
          - remember, will use many different starting piles (all with 4 piles, though)

       - NIM tournament in class next Tuesday

  • DFA vs. NFA
       - DFAs must have a transition for each letter in alphabet to exactly one state
       - NFAs for each letter in the alphabet can have zero, one or *more* transitions to other states
       - NFAs can also have \lambda transitions which move to a different state without reading a character

  • number representation
       - when you type:

          >> x = 17
       
          how does the computer actually store this information, specifically the number 17?

       - if you look far enough down into the details of what's going on when you run your computer, almost everything is represented using binary, i.e. some combination of 1's and 0's
       - why binary?
          - a combination of ease of use and cost
          - basic idea: "1" electrical current is flowing, "0" current is not flowing
          - transistors can do built to do this efficiently, cheaply and at a extremely small scale
          - could do other representations, but this is what is most effective right now... (and has been for a long time)
       
  • decimal numbers
       - most commonly used number systems have a "base"
          - each digit in the number can range from 0...base-1
          - each digit in the number has an index, starting at the right-most digit with 0 and working up to the left
          - the contribution of the digit is:

             base^index * value

          - by summing up the contribution of all of the digits, we get the value of the number
       
       - what is the base for our numbering system?
          - 10

          - for example
             - 245 = 5*10^0 + 4*10^1 + 2*10^2
             - 80498 = 8*10^0 + 9*10^1 + 4*10^2 + 0*10^3 + 8*10^4

  • binary numbers
       - we can represent numbers using any base we want
       - binary numbers are numbers represented as base 2
          - digits can only be a 0 or a 1

          - for example, the following binary numbers:
             - 101 = 1*2^0 + 0*2^2 + 1*2^2 = 5
             - 11 = 1*2^0 + 1*2^1 = 3
             - 10111 = 1*2^0 + 1*2^1 + 1*2^2 + 0*2^3 + 1*2^4 = 23
             - 100001 = 1*2^0 + 1*2^5 = 33

  • some number examples (DFA) (look in DFA examples)
       - greater_5.jff: all numbers 5 or greater (represented as binary)

       
       - odd_number.jff: all odd numbers (represented as binary)
          - (O|1)*1

  • play with JFLAP

  • design a DFA that accepts 0^n1^n
       - First hint that this is a problem is that we can't represent this as a regular expression
       - seems like we need to count the number of zeros
          - problem is we could have any number of 0s

  • turing machines
       - similar to DFAs
          - they have states with transitions defined over the alphabet
          - they have a starting state and one or more final/accepting states
       - key differences:
          - Can *write* to the input tape as well as read
          - Can more right *and* left on the input tape
          - The input tape is infinite!

  • look at the 0n1n example (found in turing examples)
       - transitions are labeled with three things:
          1) the input character read
          2) the output character to write
          3) which way to move the head (L, R or S)

       - basic idea of this example:
          - put Xs over the 0s. For each X you put on a 0, go find the next 1 and put a Y over it
          - if you get to the point where everything is X and Y (and no 0s or 1s) you're done!

       - slightly more detailed
          - read a 0: put an X down and move right
          - keep reading 0s and Ys to the right until you find a 1
          - put a Y on that 1 and move left
          - keep reading Ys and 0s until you find an X
          - move right
          - repeat
             - if you get to a point where the first character is a Y
             - read all the Ys and move right
             - make sure that you get a blank (and not a 1 or a 0). If so, we're done!

  • look at eq1s0s (found in turing examples)

  • look at palindrome (found in turing examples)