Harvey Mudd College
Computer Science 60
Assignment 12, Due Sunday, April 23, by midnight

Finite State Automata




In this assignment you will be examining the abilities and limitations of computers. We will model a computer by a finite automaton and will examine which languages can be accepted by these machines and which cannot. In addition, you will be building a turing machine to accept a language which no finite-state automaton accepts. All of the machines will be built with the help of a Java-based graphical interface called JFLAP, described in detail below.

Important submission directions!

You will not need to submit any files for this assignment with the cs60submit command. However, these seven problems will require you to create seven files -- be sure you create those files in the a12 subdirectory of your cs60 directory.

Please make sure your files are named as described in the problems below -- after the assignment is due, we will run a script that copies your files of those names to another directory to be graded.

Important JFLAP directions!

JFLAP's java code is in /cs/cs60/jflap. In order to use it, you will need to edit your .cshrc file. In particular, find the line in your .cshrc file that looks like:

setenv CLASSPATH .
(or something similar to this). At the end of this line add :/cs/cs60/jflap so that the line now reads
setenv CLASSPATH .:/cs/cs60/jflap
This will allow java to find JFLAP. Now type source .cshrc and you'll be all set!

JFLAP!

You will be using the JFLAP Automata Simulator developed by Dr. Susan Rodger at Duke University. JFLAP allows you to create automata on the screen and then simulate them with any input string you like. You must be running JFLAP from one the terminals in the CS lab or from a machine that supports Xwindows (or an emulator). In any case, JFLAP works best with a 3-button mouse but is usable with a 2-button mouse.

You can invoke JFLAP by simply typing java JFLAP. A small square menu will appear on your screen. Select the top item Finite State Automaton by clicking on it. Now you'll get a large display in which you can create deterministic or nondeterministic finite automata. The Help menu is useful. Read through it for tips. It takes less than ten minutes. Here are some quick pointers: For each of the problems below, you should assume that the input will consist of zero or more 0's and 1's. Remember that the DFA must accept every word in the language and reject every word not in the language. Finally, the empty string corresponds to no input at all. Note that if the language L is the set of all strings with an even number of 1's, then the empty string is in this language since it has zero 1's and zero is even! Thus, a DFA for this language must have the initial state be a final state, so that it accepts even if it gets no input!

  1. (2 pts.) In JFLAP, construct a DFA (deterministic finite automaton) for the language:
      {w | w contains at least three 1's.}
      
    For example, the string 011010 is in the language but the empty string and 01100 are not. Remember that DFAs must contain a transition from every state for each symbol in the alphabet (in our case the possible symbols are 0 and 1). Save your DFA in a file called part1.FA.

  2. (2 pts.) In JFLAP, construct a DFA for the language:
      {w | w contains at least two 0's and at most one 1.}
      
    For example, the string 01000 is in the language but 01 and 0110 are not. Save your DFA in a file called part2.FA.

  3. (2 pts.) In JFLAP, construct a DFA for the language:
      {w | w is any string other than 11 and 111.}
      
    For example 0111 is in the language. The only strings not in the language are 11 and 111. Save your DFA in a file called part3.FA.

  4. (9 pts.) In JFLAP, construct a DFA for the language:
      {w | w is the binary representation of a positive integer divisible by 6.}
      
    For example, 0, 0110, and 10010 are in the language, but the empty string, 10, and 0100 are not. (Leading zeros don't affect the binary representation.) (Hint: you might want to try to construct a DFA which accepts binary strings that represent integers divisible by 3 first.) Save your FA in a file called part4.FA.

  5. (5 pts.) In JFLAP, construct a finite automaton (NFA or DFA) for the language:
      {w | w contains the pattern 00 or 11 or both.}
      
    For example, 1001 should be accepted as should 10110. However, 0101 would not be accepted. Note that JFLAP is just as happy to make NFA's and DFA's. It simply permits you to have multiple outgoing transitions with the same label. Recall that nondeterministic machines do not need to have a transition for each possible input at each state. Try to use as few transitions as possible! Save this NFA in a file called part5.FA.

  6. (10 pts.) In JFLAP, construct a finite automaton (NFA or DFA) for the language:
      {w | The number of 0's in w is a multiple of 3 or a multiple of 5 or both.}
      
    A straightforward approach to this problem uses at least 15 states. Try to use as few states as possible in your FA. Save your FA in a file called part6.FA

  7. Turing Machines
    (20 pts.) Consider the language
      L = { w | w contains only 0's and the length of w is a power of 2 }.
      
    That is, the language contains all strings of 0's whose length is a power of 2.

Extra Credit

Extra credit will be given for solutions to part 7 that use fewer than eight states, up to 20% for a solution using only 3 states -- which can be done, even using one of those states as the accepting state! However, you will have to write symbols other than 0 and 1 to the tape to reduce the number of states very far.

If you find a solution with 3 states, you must have a flair for optimizations -- so additional bonus credit (20%) is available for the fewest different symbols used (I do not know what the theoretical minimum is for this, but would like to!)

Reading

Finite state machines (and the languages they accept) are considered in Chapter 12 of the text.

Submission

You will not be using cs60submit in this assignment. Instead, you should save your JFLAP files (with names part1.FA to part6.FA and part7.TM) in the a12 directory of your cs60 directory. We will grade the assignments by running a script that copies your files into a local cs60grad directory when the assignment is due.