CS52 - Spring 2017 - Class 21

Lecture notes

  • admin
       - start making progress on assignment 8

  • models of computation
       - going to look at some very simple models of computation
          - much simpler than modern computers
       
       - why simple models?
          - they're much easier to understand
          - allow us to reason and think about them
          
       - even though they're simple models, many of them can be shown to have similar capabilities as modern computers (just not as fast :)
          - therefore, reasoning about these simplified models will (in some cases) allow us to reason about computational power of computers (and other similar things)

       - answer questions like:
          - What are the capabilities and limitations of computers?
          - E.g. are there problems that we could NEVER (even given an infinite amount of time, memory, etc.) answer with a computer?
          
       - slightly different than complexity theory and reasoning about runtime

  • languages
       - a language (L) is a set of strings

       - strings in that language are built up from an alphabet of characters, often denoted \sigma

       - we want to ask a simple question:
          - given a string of characters in \sigma does it belong to the language L

  • deterministic finite automata (DFA)
       - basic idea
          - we have a set of states (indicated by circles)
          - we have a start state where computation begins (indicated by a triangle/arrow next to the state)
          - we have a collection of final states (indicated by states with an inner circle)
          - for each state and each letter in our alphabet, we have a transition to another state
             - Note it's critical that for each state there is exactly one transition for each letter in the alphabet
                 - If not, then if we encountered that letter we wouldn't know what to do!

       - computing
          - we have a string as input on a tape
          - we start at the beginning of the string
          - read a symbol from the tape and transition to the state indicated by the model
          - if:
             - we end in a final state (i.e. when we get to the end of the string we are in a final state) we accept the string
             - otherwise, if when we get to the end of the string/tape and we're in a non-final state we reject

       - all strings accepted by a DFA define a language

       - look at bbab DFA (found in DFA examples)
          - We can run different strings through the DFA

          - For example: abbbaabab
             start in q0
             a -> q0
             b -> q1
             b -> q2
             b -> q2
             a -> q3
             a -> q3
             b -> q4
             a -> q4
             b -> q4

             - We accept the string

          - What about the following:
             - aabab
                - reject (finishes in state q2)
             - bbb
                - reject (finishes in state q2)
             - babbab
                - accept
             - aabbaab
                - accept
             - aaa
                - reject (finishes in state q0)

          - what language (in English) does this define)?
             - all strings with bbab as a subsequence, possibly with characters in between

  • formal definition of DFAs
       - defined by 5 things
          - \sigma: alphabet
          - Q: set of states
          - q_start: starting state
          - F \subset Q: final states
          - \delta: state transition function
             - Q x \sigma -> Q
             - transitions for each state for each letter in the alphabet to some other state
             - often written as a table

  • some DFA examples (found in DFA_examples)
       - no_a (1): Strings of a's and b's with no a's
          - b*
       
       - even_a (2): Strings of a's with an even number of a's
          - (aa)*

       - 5a (3): Strings with a's that are multiples of 5
          - (aaaaa)*

       - one_a (4): Strings with only one a
          - b*ab*

       - start_a (5): all strings that start with a
          - a(a|b)*

       - BREAK INTO GROUPS AND SOLVE:
          - start_end: Strings that start and end with the same letter
             - (a(a|b)*a)|(b(a|b)*b)|a|b

          - odd: odd length strings
             - (a|b)((a|b)(a|b))*

          - two_a: strings with two or more a's
             - (a|b)*a(a|b)*a(a|b)*

          - two_exact_a: strings with exactly two a's
             - b*ab*ab*

          - ab: some number of repetitions of ab
             - (ab)*

  • regular expressions
       - another way of expressing a language
       - *not* a computational model
       - built from three key things:
          * (kleene star): 0 or more repetitions
          | : union or "or" (has lowest precedence)
          () : used to enforce precedence
       - for each of the examples above, I have written a corresponding regular expression below it that also describes the language