0% found this document useful (0 votes)
48 views12 pages

2 LanguagesBasics

The document defines some basic concepts about languages and strings: 1) A language is a set of strings defined over an alphabet. Strings are sequences of letters and can be concatenated. 2) Common operations on strings include concatenation, reversing, computing length and substrings. Prefixes and suffixes are also defined. 3) Languages are subsets of all possible strings from an alphabet. Operations like union, intersection and complement can be performed on languages. Operations like reverse and concatenation are also defined for languages.

Uploaded by

Usman Ali
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
48 views12 pages

2 LanguagesBasics

The document defines some basic concepts about languages and strings: 1) A language is a set of strings defined over an alphabet. Strings are sequences of letters and can be concatenated. 2) Common operations on strings include concatenation, reversing, computing length and substrings. Prefixes and suffixes are also defined. 3) Languages are subsets of all possible strings from an alphabet. Operations like union, intersection and complement can be performed on languages. Operations like reverse and concatenation are also defined for languages.

Uploaded by

Usman Ali
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 12

Languages

A language is a set of strings


St in : A sequence
String:
s
n of
f lletters
tt s
Examples: cat, dog, house,
D fi d over an alphabet:
Defined
l h b

= {a, b, c,K, z}
2

Alphabets and Strings


We will use small alphabets:

= {a, b}

Strings

a
ab

u = ab

abba
baba
aaabbbaabab

v = bbbaaa
w = abba

String Operations

w = a1a2 L an

abba

v = b1b2 Lbm

bbbaaa
Concatenation

wv = a1a2 L anb1b2 Lbm

abbabbbaaa
4

w = a1a2 L an

ababaaabbb

Reverse

w R = an L a2a1

bbbaaababa
5

String Length

w = a1a2 L an
Length:

w =n

Examples:

abba = 4
aa = 2
a =1
6

Length of Concatenation

uv = u + v
Example:

u = aab, u = 3
v = abaab, v = 5
uv = aababaab = 8
uv = u + v = 3 + 5 = 8
7

Empty String
A string with no letters:

Observations:

=0
w = w = w
abba = abba = abba
8

Substring
Substring of string:
a subsequence of consecutive characters
String

Substring

abbab

ab

abbab
abbab
abbab

abba
b
bbab
9

Prefix and Suffix

abbab

Prefixes

a
ab
abb
bb
abba
abbab

Suffixes

abbab
bb b
bbab
bab
abb
b

w = uv
prefix
suffix

10

Another Operation

wn = ww
w
L
1
42
4
3
n

Example:

D finiti n:
Definition:

(abba )2 = abbaabba
w0 =

(abba )0 =
11

The * Operation

* : the set of all possible strings from


alphabet
= {a, b}
* = { , a, b, aa, ab, ba, bb, aaa, aab,K}

12

The + Operation

+ : the set of all possible strings from


alphabet except
= {a, b}
* = { , a, b, aa, ab, ba, bb, aaa, aab,K}
+ = *
+ = {a, b, aa, ab, ba, bb, aaa, aab,K}
13

Languages
A language is any subset of

Example:

= {a, b}
* = { , a, b, aa, ab, ba, bb, aaa,K}

L n u
Languages:
s:

{}
{a, aa, aab}
{ , abba, baba, aa, ab, aaaaaa}
14

Note that:
Sets

= { } {}

Set size

{} = = 0

Set size

{} = 1

String length

=0
15

Another Example
An infinite language

L = {a n b n : n 0}

ab
aabb
aaaaabbbbb

abb L

16

Operations on Languages
The usual set operations

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


{a, ab, aaaa} I {bb, ab} = {ab}
{a, ab, aaaa} {bb, ab} = {a, aaaa}
C mpl m nt:
Complement:

L = * L

{a, ba} = { , b, aa, ab, bb, aaa,K}


17

Reverse
Definition:
Examples:

LR = {w R : w L}

{ab, aab, baba}R = {ba, baa, abab}


L = {a nb n : n 0}
LR = {b n a n : n 0}
18

Concatenation
Definition:

Example:

L1L2 = {xy : x L1, y L2 }

{a, ab, ba}{b, aa}


= {ab, aaa, abb, abaa, bab, baaa}
19

Another Operation
Definition:

Ln = 1
LL2
L
L3
n

{a, b}3 = {a, b}{a, b}{a, b} =


{aaa, aab, aba, abb, baa, bab, bba, bbb}
Sp ci l case:
Special
c s : L0 = {}

{a , bba , aaa }0 = {}
20

10

More Examples

L = {a nb n : n 0}

L2 = {a nb n a mb m : n, m 0}
aabbaaabbb L2
21

Star-Closure (Kleene *)
Definition:

L* = L0 U L1 U L2 L

Example:

a, bb,

{a, bb}* =

aa
abb
bba
bbbb
,
,
,
,

aaa, aabb, abba, abbbb,K


22

11

Positive Closure
Definition:

L+ = L1 U L2 U L
= L * { }

bb,
a,,bb

{a, bb}+ = aa, abb, bba, bbbb,

aaa, aabb, abba, abbbb,K

23

12

You might also like