0% found this document useful (0 votes)
241 views

Theory of Computation Lect1-2

1. The document describes models of computation including finite automata, pushdown automata, and Turing machines. 2. It provides examples of simple "computers" using switches and light bulbs to demonstrate the basic concepts of inputs, outputs, states, and actions. 3. The concepts of formal languages and automata theory are introduced, including strings, alphabets, and language operations like concatenation and Kleene closure. Languages are defined as sets of strings.

Uploaded by

Anik
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
241 views

Theory of Computation Lect1-2

1. The document describes models of computation including finite automata, pushdown automata, and Turing machines. 2. It provides examples of simple "computers" using switches and light bulbs to demonstrate the basic concepts of inputs, outputs, states, and actions. 3. The concepts of formal languages and automata theory are introduced, including strings, alphabets, and language operations like concatenation and Kleene closure. Languages are defined as sets of strings.

Uploaded by

Anik
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 40

Formal Languages

Models of Computation
Computation

CPU memory

2
temporary memory

input memory
CPU
output memory

Program memory

3
3
Example: f ( x)  x

temporary memory

input memory
CPU
output memory
Program memory
compute xx
2
compute x x
4
3
f ( x)  x

temporary memory
input memory
x2
CPU
output memory
Program memory
compute xx
2
compute x x
5
3
temporary memory f ( x)  x
z  2*2  4
f ( x)  z * 2  8
input memory
x2
CPU
output memory
Program memory
compute xx
2
compute x x
6
3
temporary memory f ( x)  x
z  2*2  4
f ( x)  z * 2  8
input memory
x2
CPU
f ( x)  8
Program memory output memory
compute xx
2
compute x x
7
Automata theory

Automata theory studies the laws of computation.

In reality, the laws of computation are not quite understood,


but automata theory is a good start.
A simple computer

H
I TC
SW

BATTERY

input: switch
output: light bulb
actions: flip switch
states: on, off
A simple “computer”

H
I TC
SW

f
BATTERY
start off on
f

input: switch
bulb is on if and only if
output: light bulb
there was an odd number of
actions: f for “flip switch” flips
states: on, off
Another “computer”

1
1 start off off
1
BATTERY 2 2 2 2
1
2 on
off 1
inputs: switches 1 and 2
bulb is on if and only if
actions: 1 for “flip switch 1”
both switches were flipped
actions: 2 for “flip switch 2” an odd number of times
states: on, off
Automaton
temporary memory

Automaton
input memory
CPU
output memory

Program memory

12
Different Kinds of Automata
Automata are distinguished by the temporary memory

• Finite Automata: no temporary memory

• Pushdown Automata: stack

• Turing Machines: random access memory

13
Finite Automaton

temporary memory

input memory
Finite
Automaton
output memory

Example: Vending Machines


(small computing power)
14
Pushdown Automaton
Stack Push, Pop

input memory
Pushdown
Automaton
output memory

Example: Compilers for Programming Languages


(medium computing power)
15
Turing Machine

Random Access Memory

input memory
Turing
Machine
output memory

Examples: Any Algorithm


(highest computing power)
16
Power of Automata

Finite Pushdown Turing


Automata Automata Machine

Less power More power


Solve more
computational problems
17
Languages

18
A language is a set of strings

String: A sequence of letters

Examples: “cat”, “dog”, “house”, …

Defined over an alphabet:


   a, b, c, , z

19
Alphabets and Strings
We will use small alphabets:    a, b

Strings
a
ab u  ab
abba v  bbbaaa
baba w  abba
aaabbbaabab
20
String Operations

w  a1a2  an abba
v  b1b2 bm bbbaaa

Concatenation

wv  a1a2  anb1b2 bm abbabbbaaa

21
w  a1a2  an ababaaabbb

Reverse

R
w  an a2a1 bbbaaababa

22
String Length
w  a1a2  an
Length: w n

Examples: abba  4
aa  2
a 1
23
Length of Concatenation

uv  u  v

Example: u  aab, u  3
v  abaab, v  5

uv  aababaab  8
uv  u  v  3  5  8
24
Empty String
A string with no letters: 

Observations:  0

w  w  w

abba  abba  abba


25
Substring
Substring of string:
a subsequence of consecutive characters

String Substring
abbab ab
abbab abba
abbab b
abbab bbab
26
Prefix and Suffix
abbab
Prefixes Suffixes
 abbab w  uv
a bbab
prefix
ab bab
suffix
abb ab
abba b
abbab 
27
Another Operation
n
w  ww w
 
n

Example:  abba   abbaabba


2

0
Definition: w 

 abba   
0

28
The * Operation
 * : the set of all possible strings from
alphabet 

   a, b
*    , a, b, aa, ab, ba, bb, aaa, aab,

29
The + Operation
 : the set of all possible strings from

alphabet  except 

   a, b
*    , a, b, aa, ab, ba, bb, aaa, aab,


   * 

   a, b, aa, ab, ba, bb, aaa, aab,
30
Languages
A language is any subset of *

Example:    a, b
*    , a, b, aa, ab, ba, bb, aaa,

Languages:  
 a, aa, aab
{ , abba, baba, aa, ab, aaaaaa}
31
Note that:

Sets   { }  {}

Set size {}    0

Set size {}  1


String length  0
32
Another Example

n n
An infinite language L  {a b : n  0}


ab
L abb  L
aabb
aaaaabbbbb
33
Operations on Languages
The usual set operations

 a, ab, aaaa  bb, ab  {a, ab, bb, aaaa}


 a, ab, aaaa  bb, ab  {ab}
 a, ab, aaaa   bb, ab   a, aaaa
Complement: L   * L

 a, ba    , b, aa, ab, bb, aaa,


34
Reverse

R R
Definition: L  {w : w  L}

Examples:  ab, aab, baba   ba, baa, abab


R

n n
L  {a b : n  0}

R n n
L  {b a : n  0}
35
Concatenation

Definition: L1L2   xy : x  L1, y  L2 

Example:  a, ab, ba b, aa

  ab, aaa, abb, abaa, bab, baaa

36
Another Operation
Definition: n
L  LL L
n

 a, b   a, b a, b a, b 
3

 aaa, aab, aba, abb, baa, bab, bba, bbb


0
Special case: L   

 a , bba , aaa  0   
37
More Examples

n n
L  {a b : n  0}

2 n n m m
L  {a b a b : n, m  0}

2
aabbaaabbb  L

38
Star-Closure (Kleene *)

0 1 2
Definition: L*  L  L  L 

Example:
 , 
a, bb, 
 
 a, bb *   
 aa , abb, bba , bbbb, 
aaa, aabb, abba, abbbb,
39
Positive Closure

 1 2
Definition: L  L  L 
 L *   

a, bb, 
  
 a, bb  aa, abb, bba, bbbb, 
aaa, aabb, abba, abbbb,
 
40

You might also like