Automata
Homeworks for the course CS 3350, Spring 2025

General comment. The main purpose of most homeworks is to show how well you understand the algorithms.

In many cases, the resulting finite automata, pushdown automata, and Turing machines can be simplified, but please first literally apply the algorithm so that we know that you can use it.

If in addition to this, you also show how to make the corresponding Turing machine or finite automaton or whatever more concise, nothing wrong with that, the TA may even give you some extra points (if he/she has time to grade these additional things). But the most important thing is to show that you can follow the algorithm.

For simple examples that we give you as homeworks:

So, it is important to learn how to follow the algorithm.

If you deviate from the algorithm, how do we know that you learned the algorithms? It was the same with sorting.

In general:

1. (Due February 3) In class, we designed automata for recognizing integers and real numbers.

1.1. Use the same ideas to describe an automaton for a body position: sit, stand, or lie down. You start with a normal (sitting) position (N), u (up) brings you to standing (S), down (d) brings you to lying down (L), and vice versa. A sequence of ups and downs is accepted if you end up with in the normal (sitting) position.

A natural idea is to have 3 states:

The start state N is the only final state. The transitions are as follows:

1.2. Trace, step-by-step, how the finite automaton from Part 1.1 will check whether the following two words (sequences of symbols) lead back to the normal position:

1.3. Write down the tuple <Q, Σ, δ, q0, F> corresponding to the automaton from Part 1.1:

1.4. For each automaton A, let LA denote the language of all the words accepted by this automaton, i.e., of all the words for which this automaton ends up in a final state. In class, we learned a general algorithm that:

Apply this algorithm to the following two automata: A natural idea is to have 2 states for Automaton B: The state N is the starting state, and D is the only final state. The transitions are as follows:

Send solutions to Problem 1 to Melina Salazar-Perez.

Solution to Problem 1

2. (Due February 3)

Send solutions to Problem 2 to Melina Salazar-Perez.

Solution to Problem 2

3. (Due February 5) Apply the general algorithm for transforming the finite automaton into a regular language (i.e., a language described by a regular expression) to Automaton B from Problem 1.4.

Send solutions to Problem 3 to Md. Jahangir Alam.

Solution to Problem 3

4. (Due February 12) Prove that the language L of all the sequences that have exactly the same numbers of ups and downs is not regular. For example, the word uddu is in the language L, while the word duu is not in L.

Send solutions to Problem 4 to Garab Dorji.

Solution to Problem 4

5. (Due February 12) Write and test a method that simulates a general finite automaton. Your program should enable the computer to simulate any given finite automaton and then to simulate, for any given word, step-by-step, how this automaton decides whether this word is accepted by the automaton.

The input to this method should include the full description of the corresponding finite automaton:

When simulating a finite automaton, your program needs to keep track, at each moment of time, of the current state. Initially, the state is q0 -- which is described by number 0.

For this and other programming assignments, turn in the actual code and the printout of the result of testing this code.

Send solutions to Problem 5 to Garab Dorji.

6. (Due February 12) Show, step by step, how the word uddu is accepted by the following pushdown automaton that accepts all the words that have equal number of d's and u's. This pushdown automaton has 5 states:

In the stack, in addition to the bottom symbol $, we have:

Transitions are as follows:

Send solutions to Problem 6 to Garab Dorji.

Solution to Problem 6

7. (Due February 12) Show, step by step, how the following grammar describing sequences with equal number of u's and d's will generate the expression uddu. The rules are:

Send solutions to Problem 7 to Garab Dorji.

Solution to Problem 7

8. (Due February 26) In the corresponding lecture, we described an algorithm that, given a finite automaton, produces a context-free grammar -- a grammar that generate a word if and only if this word is accepted by the given automaton.

Send solutions to Problem 8 to Melina Salazar-Perez.

Solution to Problem 8

9. (Due February 26) Use a general algorithm to construct a (non-deterministic) pushdown automaton that corresponds to context-free grammar described in Problem 7. Show, step by step, how the expression uddu will be accepted by this automaton.

Send solutions to Problem 9 to Melina Salazar-Perez.

Solution to Problem 9

10. (Due March 5) Transform the grammar from Homework 7 into Chomsky normal form.

Send solutions to Problem 10 to Md. Jahangir Alam.

Solution to Problem 10

11. (Due March 5) Use the general algorithm to transform the pushdown automaton from Problem 6 into a context-free grammar. Before doing this, you need to replace each transition in which you pop and push with two transitions in which you first pop, and then push. Show, step-by-step, how the resulting grammar will generate the word ud.

Send solutions to Problem 11 to Md. Jahangir Alam.

Solution to Problem 11

12. (Due March 19) For the grammar described in Homework 7, show how the expression uddu can be represented as uvxyz in accordance with the pumping lemma for context-free grammars. Show that the corresponding word uvvxyyz will be generated by this grammar.

Send solutions to Problem 12 to Garab Dorji.

Solution to Problem 12

13. (Due March 19) A perfect arrangement would be for a student to have equal number of up and downs, and also to have a sit-and-study experience (s) for each up or down. Show that the language of all the words that have equal number of u's and d's and and twice as many s's is not context-free.

Send solutions to Problem 13 to Garab Dorji.

Solution to Problem 13

14. (Due March 19) Show, step by step, how the stack-based algorithm will transform the expression (2 + 0) * (2 − 5) into a postfix expression, and then how a second stack-based algorithm will compute the value of this postfix expression.

Send solutions to Problem 14 to Melina Salazar-Perez.

Solution to Problem 14

15. (Due March 26) Write a program that, given an arithmetic expression,

You can assume that the expression contains no variables, only numbers, and all the numbers are one-digit numbers, i.e., each of these numbers is either 0, or 1, or 2, ..., or 9. For example, your program should correctly process expressions like 2+3*4, but there is no need to process expressions like 11+22. For simplicity, assume that the only arithmetic operations are addition +, subtraction −, and multiplication *, and that there are no parentheses.

Comments:

Send solutions to Problem 15 to Md. Jahangir Alam.

16. (Due April 2) Design a Turing machine that, given a binary number n which is larger than or equal to 4, subtracts 4 from this number. Test it, step-by-step, on the example of n = 5.

Send solutions to Problem 16 to Md. Jahangir Alam.

Solution to Problem 16

17. (Due April 2) Design a Turing machine that, given a unary number n, adds 2 to this number. Test it, step-by-step, on the example of n = 0.

Send solutions to Problem 17 to Md. Jahangir Alam.

Solution to Problem 17

18. (Due April 2) Use the general algorithm to transform a finite automaton B from Homework 1.4 into a Turing machine. Show step-by-step, on an example of a word ud, how this word will be processed by your Turing machine.

Send solutions to Problem 18 to Md. Jahangir Alam.

Solution to Problem 18

19. (Due April 2) As described in the corresponding lecture, every grammar obtained from a finite automaton is LL(1). For the grammar from Homework 8, build the corresponding table. Use this table to check whether the word ud can be derived in this grammar.

Send solutions to Problem 19 to Md. Jahangir Alam.

Solution to Problem 19

20. (Due April 9) As we discussed in the corresponding lecture, a Turing machine can be described as a finite automaton with two stacks:

On the example a Turing machine that computes n − 4 for a binary number n = 5, show, step-by-step:

Send solutions to Problem 20 to Garab Dorji.

Solution to Problem 20

21. (Due April 9) Write and test a method that simulates a general Turing machine. Your program should enable the computer to simulate any given Turing machine for accepting-rejecting and then to simulate, for any given word, step-by-step, how this Turing machine decides whether this word is accepted or not.

The input to this method should include:

This program needs to keep track of a current location of the head. Initially, this location is 0.

Your program should simulate the work of the Turing machine step-by-step. Return the printout of the method, the printout of the program that you used to test this method, and the printout of the result of this testing. Feel free to use Java, C, C++, Fortran, or any programming language in which the code is understandable.

Send solutions to Problem 21 to Garab Dorji.

22. (Due April 16) Give two examples:

These examples should be different from what you learned in class and what is given in the posted lectures and in solutions to previous semesters' homeworks -- a minor difference is OK.

Send solutions to Problem 22 to Melina Salazar-Perez.

Solution to Problem 22

23. (Due April 23) What is NP? What is P? What is NP-complete? What is NP-hard? Give brief definitions. Give an example of an NP-complete problem. Is P equal to NP?

Send solutions to Problem 23 to Melina Salazar-Perez.

Solution to Problem 23

24. (Due April 23) Prove that the cubic root of 24 is not a rational number.

Send solutions to Problem 24 to Melina Salazar-Perez.

Solution to Problem 24