You are on page 1of 46

CS205

Language Theory

Time Table

Day

Time

Class Room

Monday

12:00-12:55

L201

Tuesday

10:00-10:55

CR101

Wednesday

11:00-11:55

CR101

Friday

11:00-11:55

CR101

Course Contents
Introduction
Finite Automata and regular languages
Push down Automata and Context free languages
Push down Automata
Turing Machines and Computability
Decidability, undecidability and reducibility
Computational Complexity & NP-Completeness
3

Books
Text Book: Hopcroft, John E.; Motwani, Rajeev & Ullman, Jeffrey D., Introduction to
Automata Theory, Languages, and Computation, Third Edition, Pearson Education Inc.,
New Delhi, 2007.

Reference Book: Sipser, Michael, Introduction to the Theory of Computation, Second


Edition, Cengage Learning India Pvt. Ltd., New Delhi, 2007

Marks Distribution
Quiz 1: 10%
Mid Semester: 25%
Quiz 2: 10%
*End Semester: 50%
+Class performance: 5%
*End Semester covers whole syllabus starting from
today itself
+Class performance is evaluated based on attendance
and assignments

Language Processing System


Source Program

Preprocessor

Expands macros

Modified source program

Compiler
Target assembly program

Assembler
Relocatable machine code

Linker/Loader

library files
relocatable objects

Target machine code


6

We will show later in class


How to build compilers for programming languages
Some computational problems cannot be solved
Some problems are hard to solve

Mathematical Preliminaries

Mathematical Preliminaries
Sets
Relations
Graphs
Proof Techniques

SETS
A set is a collection of elements

A {1, 2, 3}
B {train, bus, bicycle, airplane}
We write

1 A
ship B
10

Set Representations
C = { a, b, c, d, e, f, g, h, i, j, k }
C = { a, b, , k }

finite set

S = { 2, 4, 6, }

infinite set

S = { j : j > 0, and j = 2k for some k>0 }


S = { j : j is nonnegative and even }
11

A = { 1, 2, 3, 4, 5 }

U
A

6
1

7
10
Universal Set:

2
4

3
5

All possible elements


U = { 1 , , 10 }

12

Set Operations
A = { 1, 2, 3 }

B = { 2, 3, 4, 5}
A

Union

A U B = { 1, 2, 3, 4, 5 }
Intersection
U

B = { 2, 3 }

Difference
A-B={1}
B - A = { 4, 5 }

A-B
13

Complement
Universal set = {1, , 7}
A = { 1, 2, 3 }
4

A = { 4, 5, 6, 7}

A
1
5

A
2

3
7

A=A
14

{ even integers } = { odd integers }


Integers
1

odd

2
3

even

6
7

15

DeMorgans Laws

AUB=A

B=AUB

16

Empty, Null Set:


={}
SU
U

S-

=S
=

= Universal Set

=S
-S=

17

Subset
A = { 1, 2, 3}

B = { 1, 2, 3, 4, 5 }
B

Proper Subset: A

B
B

A
18

Disjoint Sets
A = { 1, 2, 3 }

B = { 5, 6}
B=

19

Set Cardinality
For finite sets
A = { 2, 5, 7 }
|A| = 3

20

Powersets
A powerset is a set of sets
S = { a, b, c }
Powerset of S = the set of all the subsets of S
2S = {

, {a}, {b}, {c}, {a, b}, {a, c}, {b, c}, {a, b, c} }

Observation: | 2S | = 2|S|

( 8 = 23 )
21

Cartesian Product

A = { 2, 4 }

B = { 2, 3, 5 }

A X B = { (2, 2), (2, 3), (2, 5), ( 4, 2), (4, 3), (4, 4) }

22

RELATIONS
R = {(x1, y1), (x2, y2), (x3, y3), }
xi R yi

23

Equivalence Relations
Reflexive:

xRx

Symmetric:

xRy

Transitive:

x R Y and y R z

yRx
xRz

Example: R = =
x=x
x=y
x = y and y = z

y=x
x=z
24

GRAPHS
A directed graph
e
node

b
edge

d
c

Nodes (Vertices)
V = { a, b, c, d, e }
Edges
E = { (a, b), (b, c), (c, a), (b, d), (d, c), (e, d) }25

Labeled Graph
6
a

1
5

e
6

2
d

26

Walk
e
b
d

a
c

Walk is a sequence of adjacent edges


(e, d), (d, c), (c, a)
27

Path
e
b
d

a
c

Path is a walk where no edge is repeated


Simple path: no node is repeated
28

Cycle

base
b
2

d
c

Cycle: a walk from a node (base) to itself


Simple cycle: only the base node is repeated
29

Euler Tour
8
b

4
a

base
e
1
2

A cycle that contains each edge once

30

Hamiltonian Cycle
5
b

4
a

base
e
1
2

A simple cycle that contains all nodes


31

Finding All Simple Paths


e

b
d

a
c

32

Step 1
e
b

f
d

a
c
(c, a)
(c, e)

33

Step 2
e
b
d

a
(c, a)

(c, a), (a, b)


(c, e)
(c, e), (e, b)
(c, e), (e, d)

34

Step 3
e
b
d

a
(c, a)

(c, a), (a, b)


(c, e)

Repeat the same

(c, e), (e, b)

for each starting node

(c, e), (e, d)


(c, e), (e, d), (d, f)

35

root

Trees

parent
leaf
child
Trees have no cycles
36

root

Level 0

Level 1
Height 3

leaf
Level 2

Level 3
37

Binary Trees

38

PROOF TECHNIQUES
Proof by induction
Proof by contradiction

39

Induction
We have statements P1, P2, P3,
If we know
for some k that P1, P2, , Pk are true
for any n >= k that
P1, P2, , Pn imply Pn+1
Then
Every Pi is true
40

Proof by Induction
Inductive basis
Find P1, P2, , Pk which are true
Inductive hypothesis
Lets assume P1, P2, , Pn are true,
for any n >= k
Inductive step
Show that Pn+1 is true

41

Example
Theorem: A binary tree of height n
has at most 2n leaves.
Proof:
let l(i) be the number of leaves at level i
l(0) = 1

l(3) = 8

42

We want to show: l(i) <= 2i


Inductive basis
l(0) = 1

(the root node)

Inductive hypothesis
Lets assume l(i) <= 2i for all i = 0, 1, , n
Induction step
we need to show that l(n + 1) <= 2n+1

43

Induction Step

Level
n

hypothesis: l(n) <= 2n

n+1

44

Induction Step

Level
n

hypothesis: l(n) <= 2n

n+1
l(n+1) <= 2 * l(n) <= 2 * 2n = 2n+1

45

Proof by Contradiction
We want to prove that a statement P is true
we assume that P is false
then we arrive at an incorrect conclusion
therefore, statement P must be true

46

You might also like