CS52 - Assignment 10

Similar documents
Converting a DFA to a Regular Expression JP

CS402 Theory of Automata Solved Subjective From Midterm Papers. MIDTERM SPRING 2012 CS402 Theory of Automata

Last lecture CMSC330. This lecture. Finite Automata: States. Finite Automata. Implementing Regular Expressions. Languages. Regular expressions

CS103 Handout 14 Winter February 8, 2013 Problem Set 5

CMPSCI 250: Introduction to Computation. Lecture 20: Deterministic and Nondeterministic Finite Automata David Mix Barrington 16 April 2013

CSE 105 THEORY OF COMPUTATION

Formal Languages and Compilers Lecture VI: Lexical Analysis

CS/ECE 374 Fall Homework 1. Due Tuesday, September 6, 2016 at 8pm

1. (10 points) Draw the state diagram of the DFA that recognizes the language over Σ = {0, 1}

Interpreter. Scanner. Parser. Tree Walker. read. request token. send token. send AST I/O. Console

1. Draw the state graphs for the finite automata which accept sets of strings composed of zeros and ones which:

CS2 Practical 2 CS2Ah

6 NFA and Regular Expressions

JNTUWORLD. Code No: R

R10 SET a) Construct a DFA that accepts an identifier of a C programming language. b) Differentiate between NFA and DFA?

Theory of Computation Dr. Weiss Extra Practice Exam Solutions

Lexical Analysis. Lexical analysis is the first phase of compilation: The file is converted from ASCII to tokens. It must be fast!

Homework 1 Due Tuesday, January 30, 2018 at 8pm

lec3:nondeterministic finite state automata

Regular Languages and Regular Expressions

Skyup's Media. PART-B 2) Construct a Mealy machine which is equivalent to the Moore machine given in table.

CS103 Handout 13 Fall 2012 May 4, 2012 Problem Set 5

Automata & languages. A primer on the Theory of Computation. The imitation game (2014) Benedict Cumberbatch Alan Turing ( ) Laurent Vanbever

Automata Theory TEST 1 Answers Max points: 156 Grade basis: 150 Median grade: 81%

I have read and understand all of the instructions below, and I will obey the Academic Honor Code.

COMP Logic for Computer Scientists. Lecture 25

User s Guide: JFLAP Finite Automata Feedback/Grading Tool

CS 403 Compiler Construction Lecture 3 Lexical Analysis [Based on Chapter 1, 2, 3 of Aho2]

Implementation of Lexical Analysis

CT32 COMPUTER NETWORKS DEC 2015

Material from Recitation 1

Lexical Analysis. Lecture 2-4

Midterms Save the Dates!

Midterm Exam II CIS 341: Foundations of Computer Science II Spring 2006, day section Prof. Marvin K. Nakayama

NFAs and Myhill-Nerode. CS154 Chris Pollett Feb. 22, 2006.

Final Exam 1, CS154. April 21, 2010

CSE450. Translation of Programming Languages. Lecture 20: Automata and Regular Expressions

Lecture 2 Finite Automata

Finite Automata. Dr. Nadeem Akhtar. Assistant Professor Department of Computer Science & IT The Islamia University of Bahawalpur

Automating Construction of Lexers

Midterm I (Solutions) CS164, Spring 2002

Exercise 2: Automata Theory

Announcements! P1 part 1 due next Tuesday P1 part 2 due next Friday

Finite automata. We have looked at using Lex to build a scanner on the basis of regular expressions.

Context-Free Grammars

Lexical Analysis. Lecture 3-4

CS143 Handout 20 Summer 2011 July 15 th, 2011 CS143 Practice Midterm and Solution

Final Examination: Topics and Sample Problems

Informatics 1 - Computation & Logic: Tutorial 5

Concepts Introduced in Chapter 3. Lexical Analysis. Lexical Analysis Terms. Attributes for Tokens

CS2 Language Processing note 3

Regular Expressions. Computer Science and Engineering College of Engineering The Ohio State University. Lecture 9

Languages and Compilers

CS103 Handout 35 Spring 2017 May 19, 2017 Problem Set 7

CpSc 421 Final Solutions

CSCI S-Q Lecture #13 String Searching 8/3/98

Lexical Analysis. Chapter 2

Compiler Design. 2. Regular Expressions & Finite State Automata (FSA) Kanat Bolazar January 21, 2010

Formal Definition of Computation. Formal Definition of Computation p.1/28

Lexical Analysis. Implementation: Finite Automata

Compiler Construction

Chapter 3: Lexing and Parsing

CS 135 Lab Assignments Week 1

Regular Languages. MACM 300 Formal Languages and Automata. Formal Languages: Recap. Regular Languages

Chapter Seven: Regular Expressions

14.1 Encoding for different models of computation

Introduction to Lexing and Parsing


Models of Computation II: Grammars and Pushdown Automata

Universal Turing Machine Chomsky Hierarchy Decidability Reducibility Uncomputable Functions Rice s Theorem Decidability Continued

CS103 Handout 39 Winter 2018 February 23, 2018 Problem Set 7

Context-Free Grammars

HKN CS 374 Midterm 1 Review. Tim Klem Noah Mathes Mahir Morshed

QUESTION BANK. Formal Languages and Automata Theory(10CS56)

Limitations of Algorithmic Solvability In this Chapter we investigate the power of algorithms to solve problems Some can be solved algorithmically and

CS52 - Assignment 8. Due Friday 4/15 at 5:00pm.

Theory Bridge Exam Example Questions Version of June 6, 2008

Languages and Models of Computation

Formal Languages and Compilers Lecture IV: Regular Languages and Finite. Finite Automata

Lexical Analysis. COMP 524, Spring 2014 Bryan Ward

Lexical Analysis. Finite Automata. (Part 2 of 2)

UNIT I PART A PART B

Zhizheng Zhang. Southeast University

COMP 330 Autumn 2018 McGill University

CSCE 314 Programming Languages

COMP-421 Compiler Design. Presented by Dr Ioanna Dionysiou

(a) R=01[((10)*+111)*+0]*1 (b) ((01+10)*00)*. [8+8] 4. (a) Find the left most and right most derivations for the word abba in the grammar

Dr. D.M. Akbar Hussain

for (i=1; i<=100000; i++) { x = sqrt (y); // square root function cout << x+i << endl; }

2010: Compilers REVIEW: REGULAR EXPRESSIONS HOW TO USE REGULAR EXPRESSIONS

Turing Machine Languages

Compiler Construction LECTURE # 3

CSE450. Translation of Programming Languages. Automata, Simple Language Design Principles

, has the form T i1i 2 i m. = κ i1i 2 i m. x i1. 1 xi2 2 xim m (2)

Week 2: Syntax Specification, Grammars

Introduction; Parsing LL Grammars

Mastering Binary Math

Recursively Enumerable Languages, Turing Machines, and Decidability

Front End: Lexical Analysis. The Structure of a Compiler

Regular Languages (14 points) Solution: Problem 1 (6 points) Minimize the following automaton M. Show that the resulting DFA is minimal.

Transcription:

CS52 - Assignment 10 Due Wednesday 12/9 at 7:00pm https://xkcd.com/205/ Important Notice Assignments 9 and 10 are due at the same time. This is to give you maximum flexibility in scheduling during the busy end of semester. It would be a serious mistake to attempt to begin either assignment in the few hours before it is due. Please plan ahead! For this assignment you will be playing with the JFLAP automata tool to design DFAs, NFAs and turing machines. Each problem, except for number 5, requires you to construct a finite state automaton or a Turing machine. When you start JFLAP, select Finite State Automaton or Turing Machine, as appropriate. Construct your machine and use FJLAP to test it before saving it. Then save your JFLAP machine in a file named assign10- one-digit-problem-number.jff For example, the file for Problem 3 would be named assign10-3.jff. Problem 5 is an exception; it asks for a text file named assign10-5.txt. 1

Obtaining JFLAP We will use a Java-based program, called JFLAP, that we ve been playing with in class. It was written by Professor Susan Rodger of Duke University. If you re working, use execute the following command in terminal: /common/cs/cs052/bin/jflap If you re working on your own computer, you can obtain it at: http://www.jflap.org/ Click on the tab to the left Get JFLAP, fill out the form and then download version 7.0 (NOT the beta version, 8.0). The Thin version should work, but if it doesn t, try downloading the full version. Once you download the.jar file you should only need to doubleclick on it for it to run. Even if you don t plan on doing the assignment early, make sure to download JFLAP ASAP and make sure that it works on your computer. If you need help using JFLAP, select the Help menu from the program or you can view a tutorial online at http://www.jflap.org/. Finite Automota 1. [2 poitns] Abba (would not be accepted) Use JFLAP to construct a DFA that accepts all non-empty strings over the alphabet {a, b} in which every other letter in the string is an a, starting with the first letter. The empty string should not be accepted, but ab and aaa should be. 2. [2 points] aaaaaah Use JFLAP to construct a six-state DFA which accepts a string over the one-letter alphabet {a} if it has a number of a s that is a multiple of 2 or a multiple of 3 (or both). 3. [2 points] 7 is the magic number Use JFLAP to construct a DFA which accepts a string of 0 s and 1 s if, when interpreted as a binary number, is a multiple of 7. The binary representation is read from left to right; that is, the most significant bit comes first. Advice: This is not trivial; think about it before you start to build the DFA. Write out a bunch of examples and try and identify the pattern. Hint: The key is to think about this as a math problem and not a pattern matching problem. In assignment 8, problem 1, when you were processing bytes from left to right you were able to calculate a partial value for the byte so far. Think of trying to do something similar, since we ll be reading the bits off the string from left to right, one at a time. 2

4. [3 points] Abba (would be accepted) Consider strings constructed over the alphabet {a, b}. The string aabbbab has two occurrences of the substring ab and one occurrence of the substring ba. The string aba has one occurrence of ab and one of ba; it does not matter that they share a character. Use JFLAP to construct a DFA that accepts strings for which the number of times ab appears is equal to the number of times that ba appears. 5. [3 points] If you squint, maybe you can distinguish them Two strings s and t are distinguishable over a language L if there is a third string u such that exactly one of su and tu are in L. (a) Find six strings which are pairwise distinguishable over the language of Problem 2 and show that they are in fact distinguishable. With six strings, there are fifteen pairs to check. (b) Any DFA that accepts the language (from Problem 2) must have at least six states. Justify this statement. For this problem, submit a separate file (plain text, not a Word document or a PDF file) named assign10-5.txt. 6. [2 points] aaaaah Use JFLAP to create a nondeterministic finite automaton that has eight states and accepts the strings over a one-letter alphabet {a} whose length is a multiple of 2 or a multiple of 5 (or both). Notice that the technique you used in Problem 2 leads to a DFA with ten states. Turing Machines For the last two problems you will be creating Turing machines. Keep your Turing machines as simple as possible. Your Turing machines should have exactly one accepting state and one rejecting state, even though JFLAP does not enforce that requirement. In fact, JFLAP does not have explicit rejecting states; you can create a rejecting state by making a non-accepting state that has no transitions out of it. 7. [3 points] There are 11 kinds of people in the world, those that understand unary and those that don t Binary numbers consists of 0 s and 1 s. Unary numbers consist only of 1 s. For example, we represent 1 as 1 in unary, 2 as 11, 3 as 111, etc. Write a Turing machine over the alphabet {1, } that accepts all unary number subtraction problems where the result is positive, i.e greater than 0. For example, 111-11 would be accepted while 11-111 would be rejected. Also, any string without a minus sign, or one with more than one minus sign, will be rejected. 8. [3 points] (Almost there!) Construct a turing machine over the input alphabet of parentheses, i.e. ) and (, that recognizes the language of all strings of properly balanced parentheses (equal number of open 3

and close parentheses and the open parentheses must come before the corresponding close parentheses). For example () (()) (()((()()))) would all be members of the language, while )( (() ())( would NOT be members of the language. When you re done You should have a separate file for each problem. Submit each of these files separately using the normal submission mechanism. 4

https://xkcd.com/505/ 5