0% found this document useful (0 votes)
27 views78 pages

Languages

This document defines and explains the concepts of strings, languages, and finite automata. It begins by defining strings as sequences of letters over an alphabet. It introduces common string operations like concatenation and reversal. It then defines languages as sets of strings and explores properties of languages like closures. The document concludes by introducing finite automata as machines that accept or reject strings as inputs based on state transitions. It provides examples of finite automata diagrams and explains how they are used to model languages by reading input strings and transitioning between states.
Copyright
© © All Rights Reserved
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)
27 views78 pages

Languages

This document defines and explains the concepts of strings, languages, and finite automata. It begins by defining strings as sequences of letters over an alphabet. It introduces common string operations like concatenation and reversal. It then defines languages as sets of strings and explores properties of languages like closures. The document concludes by introducing finite automata as machines that accept or reject strings as inputs based on state transitions. It provides examples of finite automata diagrams and explains how they are used to model languages by reading input strings and transitioning between states.
Copyright
© © All Rights Reserved
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/ 78

1

Languages
2
A language is a set of strings

String: A sequence of letters

Examples: cat, dog, house,

Defined over an alphabet:

Languages
{ } z c b a , , , , = E
3
Alphabets and Strings
We will use small alphabets:

Strings

abba w
bbbaaa v
ab u
=
=
=
{ } b a, = E
b aaabbbaaba
baba
abba
ab
a
4
String Operations
m
n
b b b v
a a a w

2 1
2 1
=
=
bbbaaa
abba
m n
b b b a a a wv
2 1 2 1
=
Concatenation
abbabbbaaa
5
1 2
a a a w
n
R
=
n
a a a w
2 1
=
ababaaabbb
Reverse
bbbaaababa
6
String Length


Length:


Examples:

n
a a a w
2 1
=
n w =
1
2
4
=
=
=
a
aa
abba
7
Recursive Definition of Length
For any letter:

For any string :

Example:
1 = a
1 + = w wa
wa
4
1 1 1 1
1 1 1
1 1
1
=
+ + + =
+ + + =
+ + =
+ =
a
ab
abb abba
8
Length of Concatenation



Example:
v u uv + =
8 5 3
8
5 ,
3 ,
= + = + =
= =
= =
= =
v u uv
aababaab uv
v abaab v
u aab u
9
Proof of Concatenation Length
Claim:

Proof: By induction on the length


Induction basis:

From definition of length:
v u uv + =
v
1 = v
v u u uv + = + = 1
10
Inductive hypothesis:

for



Inductive step: we will prove

for
v u uv + =
n v , , 2 , 1 =
1 + = n v
v u uv + =
11
Inductive Step
Write , where

From definition of length:


From inductive hypothesis:


Thus:

wa v =
1 , = = a n w
1
1
+ =
+ = =
w wa
uw uwa uv
w u uw + =
v u wa u w u uv + = + = + + = 1
12
Empty String
A string with no letters:


Observations:

abba abba abba


w w w
= =
= =
=


0
13
Substring
Substring of string:
a subsequence of consecutive characters

String Substring
bbab
b
abba
ab
abbab
abbab
abbab
abbab
14
Prefix and Suffix

Prefixes Suffixes


abbab
abbab
abba
abb
ab
a

b
ab
bab
bbab
abbab
uv w=
prefix
suffix
15
Another Operation



Example:


Definition:

n
n
w ww w =
( ) abbaabba abba =
2
=
0
w
( ) =
0
abba
16
The * Operation
: the set of all possible strings from
alphabet






* E
E
{ }
{ } , , , , , , , , , *
,
aab aaa bb ba ab aa b a
b a
= E
= E
17
The + Operation
: the set of all possible strings from
alphabet except






+
E
E
{ }
{ } , , , , , , , , , *
,
aab aaa bb ba ab aa b a
b a
= E
= E
E = E
+
*
{ } , , , , , , , , aab aaa bb ba ab aa b a = E
+

18
Language
A language is any subset of

Example:



Languages:

* E
{ }
{ } , , , , , , , , *
,
aaa bb ba ab aa b a
b a
= E
= E
{ }
{ }
} , , , , , {
, ,
aaaaaa ab aa baba abba
aab aa a

19
Another Example

An infinite language
} 0 : { > = n b a L
n n
aaaaabbbbb
aabb
ab

L e L abbe
20
Operations on Languages
The usual set operations





Complement:

{ } { }
{ } { }
{ } { } { } aaaa a ab bb aaaa ab a
ab ab bb aaaa ab a
aaaa bb ab a ab bb aaaa ab a
, , , ,
} { , , ,
} , , , { , , ,
=
=
=

L L E = *
{ } { } , , , , , , , aaa bb ab aa b ba a =
21
Reverse

Definition:

Examples:
} : { L w w L
R R
e =
{ } { } abab baa ba baba aab ab
R
, , , , =
} 0 : {
} 0 : {
> =
> =
n a b L
n b a L
n n R
n n
22
Concatenation

Definition:



Example:
{ }
2 1 2 1
, : L y L x xy L L e e =
{ }{ }
{ } baaa bab abaa abb aaa ab
aa b ba ab a
, , , , ,
, , ,
=
23
Another Operation
Definition:





Special case:

n
n
L LL L =
{ } { }{ }{ }
{ } bbb bba bab baa abb aba aab aaa
b a b a b a b a
, , , , , , ,
, , , ,
3
= =
{ }
{ } { }

=
=
0
0
, , aaa bba a
L
24
More Examples

} 0 : { > = n b a L
n n
} 0 , : {
2
> = m n b a b a L
m m n n
2
L aabbaaabbbe
25
Star-Closure (Kleene *)

Definition:


Example:





2 1 0
* L L L L =
{ }

=
, , , ,
, , , ,
, ,
,
* ,
abbbb abba aabb aaa
bbbb bba abb aa
bb a
bb a

26
Positive Closure

Definition:
{ } =
=
+
*
2 1
L
L L L
{ }

=
+
, , , ,
, , , ,
, ,
,
abbbb abba aabb aaa
bbbb bba abb aa
bb a
bb a
27
Finite Automata
28
Finite Automaton
Input
String

Output
String
Finite
Automaton
29
Finite Accepter

Input
Accept
or
Reject
String
Finite
Automaton
Output
30
Transition Graph

initial
state
final
state
accept
state
transition
Abba -Finite Accepter
0
q
1
q
2
q
3
q
4
q
a
b b
a
5
q
a
a
b
b
b a,
b a,
31
Initial Configuration

1
q
2
q
3
q
4
q
a
b b
a
5
q
a
a
b
b
b a,
Input String
a
b b
a
b a,
0
q
32
Reading the Input

0
q
1
q
2
q
3
q
4
q
a
b b
a
5
q
a
a
b
b
b a,
a
b b
a
b a,
33

0
q
1
q
2
q
3
q
4
q
a
b b
a
5
q
a
a
b
b
b a,
a
b b
a
b a,
34

0
q
1
q
2
q
3
q
4
q
a
b b
a
5
q
a
a
b
b
b a,
a
b b
a
b a,
35

0
q
1
q
2
q
3
q
4
q
a
b b
a
5
q
a
a
b
b
b a,
a
b b
a
b a,
36
0
q
1
q
2
q
3
q
4
q
a
b b
a
Output: accept
5
q
a
a
b
b
b a,
a
b b
a
b a,
37
Rejection

1
q
2
q
3
q
4
q
a
b b
a
5
q
a
a
b
b
b a,
a
b
a
b a,
0
q
38

0
q
1
q
2
q
3
q
4
q
a
b b
a
5
q
a
a
b
b
b a,
a
b
a
b a,
39

0
q
1
q
2
q
3
q
4
q
a
b b
a
5
q
a
a
b
b
b a,
a
b
a
b a,
40

0
q
1
q
2
q
3
q
4
q
a
b b
a
5
q
a
a
b
b
b a,
a
b
a
b a,
41
0
q
1
q
2
q
3
q
4
q
a
b b
a
5
q
a
a
b
b
b a,
Output:
reject
a
b
a
b a,
42
Another Example
a
b
b a,
b a,
0
q
1
q
2
q
a
b
a
43
a
b
b a,
b a,
0
q
1
q
2
q
a
b
a
44
a
b
b a,
b a,
0
q
1
q
2
q
a
b
a
45
a
b
b a,
b a,
0
q
1
q
2
q
a
b
a
46
a
b
b a,
b a,
0
q
1
q
2
q
a
b
a
Output: accept
47
Rejection
a
b
b a,
b a,
0
q
1
q
2
q
a
b b
48
a
b
b a,
b a,
0
q
1
q
2
q
a
b b
49
a
b
b a,
b a,
0
q
1
q
2
q
a
b b
50
a
b
b a,
b a,
0
q
1
q
2
q
a
b b
51
a
b
b a,
b a,
0
q
1
q
2
q
a
b b
Output: reject
52
Formalities
Deterministic Finite Accepter (DFA)
( ) F q Q M , , , ,
0
o E =
Q
E
o
0
q
F
: set of states
: input alphabet
: transition function
: initial state
: set of final states
53
Input Aplhabet

E
0
q
1
q
2
q
3
q
4
q
a
b b
a
5
q
a
a
b
b
b a,
{ } b a, = E
b a,
54
Set of States

Q
0
q
1
q
2
q
3
q
4
q
a
b b
a
5
q
a
a
b
b
b a,
{ }
5 4 3 2 1 0
, , , , , q q q q q q Q =
b a,
55
Initial State

0
q
1
q
2
q
3
q
4
q
a
b b
a
5
q
a
a
b
b
b a,
b a,
0
q
56
Set of Final States

F
0
q
1
q
2
q
3
q
a
b b
a
5
q
a
a
b
b
b a,
{ }
4
q F =
b a,
4
q
57
Transition Function

o
0
q
1
q
2
q
3
q
4
q
a
b b
a
5
q
a
a
b
b
b a,
Q Q E : o
b a,
58

( )
1 0
, q a q = o
2
q
3
q
4
q
a
b b
a
5
q
a
a
b
b
b a,
b a,
0
q
1
q
59

( )
5 0
, q b q = o
1
q
2
q
3
q
4
q
a
b b
a
5
q
a
a
b
b
b a,
b a,
0
q
60
0
q
1
q
2
q
3
q
4
q
a
b b
a
5
q
a
a
b
b
b a,
b a,
( )
3 2
, q b q = o
61
Transition Function

o
0
q
1
q
2
q
3
q
4
q
a
b b
a
5
q
a
a
b
b
b a,
o
a
b
0
q
1
q
2
q
3
q
4
q
5
q
1
q
5
q
5
q
2
q
2
q
3
q
4
q
5
q
b a,
5
q
5
q
5
q
5
q
62
Extended Transition Function

* o
Q Q E * : * o
0
q
1
q
2
q
3
q
4
q
a
b b
a
5
q
a
a
b
b
b a,
b a,
63
( )
2 0
, * q ab q = o
3
q
4
q
a
b b
a
5
q
a
a
b
b
b a,
b a,
0
q
1
q
2
q
64
( )
4 0
, * q abba q = o
0
q
1
q
2
q
3
q
4
q
a
b b
a
5
q
a
a
b
b
b a,
b a,
65
( )
5 0
, * q abbbaa q = o
1
q
2
q
3
q
4
q
a
b b
a
5
q
a
a
b
b
b a,
b a,
0
q
66
( )
5 0
, * q abbbaa q = o
1
q
2
q
3
q
4
q
a
b b
a
5
q
a
a
b
b
b a,
b a,
0
q
Observation: There is a walk from to
with label
0
q
1
q
abbbaa
67
Recursive Definition




( )
( ) ) ), , ( * ( , *
, *
a w q wa q
q q
o o o
o
=
=
0
q
1
q
2
q
3
q
4
q
a
b b
a
5
q
a
a
b
b
b a,
b a,
68




0
q
1
q
2
q
3
q
4
q
a
b b
a
5
q
a
a
b
b
b a,
b a,
( )
( )
( ) ( ) ( )
( ) ( )
( )
2
1
0
0
0
0
,
, ,
, , , *
), , ( *
, *
q
b q
b a q
b a q
b a q
ab q
=
=
=
=
=
o
o o
o o o
o o
o
69
Languages Accepted by DFAs
Take DFA

Definition:
The language contains
all input strings accepted by


= { strings that drive to a final state}
M
( ) M L
M
M ( ) M L
70
Example

0
q
1
q
2
q
3
q
4
q
a
b b
a
5
q
a
a
b
b
b a,
b a,
( ) { } abba M L =
M
accept
71
Another Example
0
q
1
q
2
q
3
q
4
q
a
b b
a
5
q
a
a
b
b
b a,
b a,
( ) { } abba ab M L , , =
M
accept accept accept

72
Formally

For a DFA

Language accepted by :



( ) F q Q M , , , ,
0
o E =
M
( ) ( ) { } F w q w M L e E e = , * : *
0
o
alphabet
transition
function
initial
state
final
states
73
Observation
Language accepted by :




Language rejected by :
( ) ( ) { } F w q w M L e E e = , * : *
0
o
M
( ) ( ) { } F w q w M L e E e = , * : *
0
o
M
74
More Examples

a
b
b a,
b a,
0
q
1
q
2
q
( ) } 0 : { > = n b a M L
n
accept
trap state
75

( ) M L = { all substrings with prefix } ab
a
b
b a,
0
q
1
q
2
q
accept
b a,
3
q
a
b
76

( ) M L
= { all strings without
substring } 001

0 00 001
1
0
1
1 0
0
1 , 0
77
Regular Languages

A language is regular if there is
a DFA such that




All regular languages form a language family

L
M
( ) M L L =
78
Example
The language
is regular:


{ } { } * , : b a w awa L e =
a
b
b a,
a
b
b
a
0
q
2
q
3
q
4
q

You might also like