CS481F01 Solutions 4 CFGs
A. Demers
10 Oct due 17 Oct
1. For each of the following languages, give a context-free grammar that generates the language.
(a)
(b)
(c)
(d)
(e)
(answer a)
cfw_ 0i 1i | i 0
cfw_ 0i 1j 0k | i = j j = k
cfw_ 0i 1j | i j 2i
cfw_
CONCORDIA UNIVERSITY
5. Prove the following statement:
DEPARTMENT OF COMPUTER SCIENCE & SOFTWARE ENGINEERING
COMP 335/4
Theoretical Computer Science
A language L is recursive if and only if both L and L are recursively
enumerable.
Winter 2015
6. Show that
COMP 345 - Advanced Program Design with C+
1
ADVANCED PROGRAM
DESIGN WITH C+
Part 2:
Data types
Joey Paquet, 2007-
COMP 345 - Advanced Program Design with C+
2
DATA TYPES
Simple data types
Pointers
Type checking
Type coercion
Joey Paquet, 2007-
COMP 345 -
FORMAL LANGUAGES, AUTOMATA AND THEORY OF COMPUTATION
EXERCISES IN CONTEXT-FREE LANGUAGES
2010
1
CONTEXT FREE LANGUAGES
& PUSH-DOWN AUTOMATA
CONTEXT-FREE GRAMMARS, CFG
Problems Sudkamp
Problem 1. (3.2.1)
Which language generates the grammar G given by the
Introduction to
Theoretical Computer Science
COMP 335
Fall 2015
Introduction and Course
Orientation
1
Course Administration
Prof: Dr. Nora Houari
Office: EV3. 231
Email: houari@encs.concordia.ca
Office hours: Fridays 10:3012:00, or by appointment
Keep
c
COMP 335:
Introduction to Theoretical
Computer Science
N. HOUARI, PHD, P. Eng.
FA L L 2 0 1 5
1
Basic Concepts
Copyright An Introduction to Formal Languages and Automata, Peter Linz
Copyright Introduction to the Theory of Computation, Michael Sipser
Copyr
COMP 335:
Closure Properties of Regular Languages
Regular Expressions
N. Houari, PhD, P.Eng.
Fall 2015
Reading Chap#3
1
NFA with Single Final State
COMP 335
2
Given any NFA, we can always convert
it into an equivalent NFA which has only
ONE final state (h
COMP 335:
Properties of Regular Languages
N. Houari, PhD, P.Eng.
Fall 2015
Reading Chap#4.2 and 4.3
1
Standard Representations
of Regular Languages
Regular Languages
DFAs
NFAs
9/29/2015
Regular
Grammars
Regular
Expressions
COMP 335
2
When we say:
it means
COMP 335:
Grammars
N. Houari, PhD, P.Eng.
Fall 2015
Reading Chap#3
1
Grammars
Grammars generate languages
Example: the English language
sentence noun _ phrase
noun _ phrase article
predicate
noun
predicate verb
COMP 335
2
article a
article the
noun cat
no
Department of Computer Science and Software Engineering
Concordia University
Introduction to Theoretical Computer Science
COMP 335
Course Outline
Fall 2015
Contact Information
Instructor: Dr. Nora Houari, EV3.231, houari@encs.concordia.ca
Schedule:
LECT E
CONCORDIA UNIVERSITY
DEPARTMENT OF COMPUTER SCIENCE & SOFTWARE ENGINEERING
COMP 335/4
Theoretical Computer Science
Winter 2015
Assignment 3
5. Construct a PDA corresponding to the context-free grammar
S SS | cfw_SX | [SY |
X
Y ]
Note that cfw_, [, ], and
Concordia University
Department of Computer Science & Software Engineering
Theoretical Computer Science
COMP 335/4
Winter 2015
Assignment 3
1. In each case, what language is generated by CFGs below. Justify your claim (prove it!)
(a) G with productions S
Section 3 Handout
CS 121
September 26, 2013
Todays Topics
Regular and Non-regular Languages
Context-Free Grammars
1
Regular and Nonregular Languages
There are countably many regular expressions over a language, but there are uncountably
many languagesso
CS481F01 Solutions 7
A. Demers
7 Dec 2001
1.
Consider the language
i
L = cfw_0i 102 | i > 0
L is the exponentiation function represented by pairs.
(a)
Prove that L is not a CFL.
Answer (a) By Parikhs Theorem, if L were context-free then it would be
lette
CS481F01 Solutions 8
A. Demers
7 Dec 2001
1. Prob. 111 from p. 344 of the text. One of the following sets is r.e. and the
other is not. Which is which?
(a)
(b)
cfw_ i | L(Mi ) contains at least 481 elements
cfw_ i | L(Mi ) contains at most 481 elements
CS481F01 Solutions 6 PDAS
A. Demers
2 November 2001
1.
(a)
Give a NPDAs that recognize the following languages:
The set of all strings in cfw_0, 1 that contain twice as many 1s as 0s.
(answer a) We build a machine that keeps on its stack the 0s or 1s that
COMP 335 Introduction to Theoretical Computer Science
Solution to Assignment 3
1. Let L be any CFL. Then, we know that there is a context-free
grammar G = (V, , S, P ) that generates L. Using G, we obtain another CFG G0 = (V, , S, P 0 ) such that if P inc
CONCORDIA UNIVERSITY
Dept. of Computer Science and Software Engineering
COMP 335 Introduction to Theoretical Computer Science
Assignment 1 Revised
Electronic Submission Due on Thursday May 14 Friday May 15th at 23:59
Note 1: This is a revised assignment;
COMP 335 Introduction to Theoretical Computer Science
Solution to Assignment 1
Q1.1. = cfw_a, b.
L1 = cfw_w : w = bxyaz and x, y, z .
b
a
a
b
a,b
Fig. 1. DFA for L1 defined in Q1
Q1.2. = cfw_a, b.
L2 = cfw_w : w and |w| = 2k + 1, k 0.
i.e., |w| = 1, 3, 5,
CONCORDIA UNIVERSITY
Dept. of Computer Science and Software Engineering
COMP 335 Introduction to Theoretical Computer Science
Assignment 3
Electronic submission is due on Friday June 5th Thursday June 11th at 23:59
NOTE: The extended due date is to allow
CONCORDIA UNIVERSITY
Dept. of Computer Science and Software Engineering
Introduction to Theoretical Computer Science
COMP335 Section AA
Summer 2015
Assignment 2
Electronic Submission Due on May 21 May 25th, 2015 at 23:59
The grade for each part is 5; the
CONCORDIA UNIVERSITY
DEPARTMENT OF COMPUTER SCIENCE & SOFTWARE ENGINEERING
COMP 335/4
Theoretical Computer Science
Winter 2015
4. Apply the Pumping Lemma to prove that the following languages are not
regular.
(a) cfw_ak bn : n = 2k
(b) cfw_an bm ak : n =
Concordia University
Introduction to Theoretical Computer Science
Winter 2015
Solution to Assignment 2 - Part II
5. If L is regular, it is accepted by some DFA, say A = (Q, , , s0 , F ). We will
construct an -NFA, such that L(B) = third(L(A). Here you nee
COMP 335:
Context-Free Grammars (CFGs)
N. Houari, PhD, P.Eng.
Fall 2015
Reading Chap#5
1
Example
A context-free grammar
G:
S aSb
S
A derivation:
S aSb aaSbb aabb
COMP 335
2
A context-free grammar
G:
S aSb
S
Another derivation:
S aSb aaSbb aaaSbbb aaabbb
Languages
9/10/2015
COMP 335
1
Alphabets and Languages
A language L is a set of strings/sentences over a
finite set of characters/symbols, called the
alphabet.
Defn. a string/sentence is a sequence of
characters (or symbols).
cat, dog, house are examples
Example
A context-free grammar
G:
S aSb
S
Context-Free Grammars (CFGs)
A derivation:
S aSb aaSbb aabb
10/10/2013
COMP 335
1
COMP 335
2
G:
S aSb
S aSb
S
A context-free grammar
S
L(G ) = cfw_a nb n : n 0
Another derivation:
S aSb aaSbb aaaSbbb aaabbb
COM
The Pumping Lemma:
For infinite context-free language
there exists an integer
More Applications
of
The Pumping Lemma
for any string
m
w L,
such that
| w | m
we can write
w = uvxyz
with lengths
| vxy | m and
and it must be:
i i
uv xy z L,
COMP 335
1
Non-co
Department of Computer Science and Software Engineering
Concordia University
COMP 335: Introduction to Theoretical Computer Science
Fall 2015
Assignment 3
Evaluation: 50 pts
(3% of your final grade)
Due date and time: Sunday, November 8th 2015 by midnight
Why Study Automata?
A survey of Stanford grads 5 years out
asked which of their courses did they
use in their job.
Basics like Programming took the top
spots, of course.
But among optional courses, Intro to
TCS stood remarkably high.
3X the score for AI,
Nondeterministic Finite Automata
A NFA can be in several states at once, or,
viewded another way, it can guess which
state to go to next
Example: An automaton that accepts all and
only strings ending in 01.
0, 1
Start
0
q0
1
q1
q2
Here is what happens whe