COMP208Lecture 1 Introduction
COMP208Lecture 1 Introduction
COMP208: Lecture 1
Introduction
11-2-2025
Automata
• Automata theory is the study of abstract
computing models, or “machines”.
Example
• if w = 10110111, then |w| = 8
• |ε|=0
Reverse of a string
• The reverse of a string u, denoted by 𝑢𝑟 , is
obtained by writing the symbols in reverse
order.
Example
if u = cabdbbca then 𝑢𝑟 = acbbdbac
Concatenation of 2 strings
The concatenation of 2 strings is the string
formed by writing the first, followed by the
second with no intervening space.
Example
let ∑ = {a, b, c, d},
u = cabdbbca v = bbabab
u and v are strings from ∑ , then
uv = cabdbbcabbabab , vu = bbababcabdbbca
Notes
1. uv ≠ vu
2. |uv | = |vu|
Question
If ∑ = {a, b, c}, u = abc and v = bcc, what is
the length of (𝑢 𝑣)𝑟
1. 12
2. 9
3. 6
Palindrome
• A palindrome is a string that reads the same
forward and backward.
Example
• The string abababa is a palindrome.
• The string baa is not a palindrome.
Properties of strings
1. |𝑢| = |𝑢𝑟 |
2. 𝑢𝜀 = 𝑢 = 𝜀𝑢
Examples
1. ∑ = {0, 1}, then the following are strings
over this alphabet:
11, 000111, 101010
2. L+ = L∗ - { ε } , if ε ∉ L
3. {ε}∗ = {ε }
4. Ø∗ = {ε }
Properties of Formal Languages
(Cont.)
5. 𝐿∗ 𝐿∗ = 𝐿∗
6. 𝐿∗∗ = 𝐿∗
7. 𝐿Ø = Ø = ØL
8. 𝐿 ε = 𝐿 = ε 𝐿
Operations on Languages
Languages have been defined above as sets of
strings, and thus the usual set-theoretic
operations can be defined by them:
If L, M ⊆ ∑ ∗ , then the operations are:
1. 𝐿 ∪ 𝑀 = { 𝑤 ∈ ∑ ∗ : w ∈ 𝐿 or 𝑤 ∈ 𝑀}
2. 𝐿 ∩ 𝑀 = { 𝑤 ∈ ∑ ∗ : w ∈ 𝐿 and 𝑤 ∈ 𝑀}
3. 𝐿 − 𝑀 = { 𝑤 ∈ ∑ ∗ : w ∈ 𝐿 and 𝑤∉𝑀}
4. 𝐿 = ∑ ∗ − L
Example
Let ∑ = {a}, the following are languages over ∑:
▪ 𝐿1 = { 𝑎𝑛 : n is odd}
▪ 𝐿2 = { 𝑎𝑛 : n is even}
▪ 𝐿3 = { 𝑎𝑛 : n is prime} 𝑎29 ∊𝐿3
▪ 𝐿4 = { 𝑎𝑛 : n ≥ 0}
Note that:
𝐿1 ∪ 𝐿2 = ∑ ∗ , 𝐿3 - {aa} ⊂ 𝐿1 , 𝐿1 ∩ 𝐿2 = Ø
Concatenation of Languages
The concatenation of 2 languages 𝐿, 𝑀 ⊆ ∑ ∗ is
the set of all strings obtained by the
concatenating any string of L with any string of
M, i.e.
𝐿𝑀 = { uv :u ∈ 𝐿 and v ∊ M }
Notes
• ∅ is a language over any alphabet.
• ∑∗ is a language over any alphabet.
• {ε} is a language over any alphabet.
• ∅ ≠ {ε}
Question
• If L={ab, bb}, which of the following words is
NOT in L*:
1. abab
2. abbb
3. bbb
4. bbab
Question
• If L={ab, bb}, which of the following words is
NOT in L*:
1. abab
2. abbb
3. bbb
4. bbab
Questions
Find L in
L {a, b} = { a, baa, b, bab}
1. L = {a, ba}
2. L= {b, ab}
3. L = {ba, ε }
Questions
Find L in
L {a, b} = { a, baa, b, bab}
1. L = {a, ba}
2. L= {b, ab}
3. L = {ba, ε }
Questions
Find L in
{a , aa, ab} L = {ab, aab, abb, aa, aaa, aba}
1. L= {a, b}
2. L = {b, ab}
3. L= {ba, ε}
Questions
Find L in
{a , ab, ε} L = {b, ab, ba, aba, abb, abba}
1. L= {a, ba}
2. L = {b, ba}
3. L= {ba, ε}
Questions
• Let ∑ = {𝑥, 𝑦, 𝑧}, A = {𝑥𝑦}, B = {ε, 𝑥}
• Determine AB, BA.
Question
• Let A= {a, b}, B={1, 2, 3}
• A x B is …. ….
• |A x B| is … …
Question
• Let A= {a, b}, B={1, 2, 3}, C = {c, d}
• A x B x C = {(a, 1, c), (a, 1, d), (a, 2, c), (a, 2,
d), (a, 3, c), (a, 3, d), (b, 1, c), (b, 1, d), (b, 2,
c), (b, 2, d), (b, 3, c), (b, 3, d)}
• |A x B x C| = |A| * |B| * |C|
= 2 * 3*2
Question
• Select a correct answer:
If A = {3, 4, 6, 7} and B = {5, 7}, which of
the following is in A x B:
1. 7
2. (7, 7)
3. (5, 6)
4. {7, 7}
Question
• If ∑ = {a, b, c}, w is a string over ∑ and |www| = 18,
what is the length of w?
1. 18
2. 12
3. 6
4. 3
Question
Let M = {a, b} and N = {aa, bb}, Find MN and M x N
• MN = {aaa, abb, baa, bbb}
• M x N = {(a, aa), (a, bb), (b, aa), (b, bb)}
Question
• Q = {a, b}, A = {2, 3}
• Find Q ∪ A and Q . A
Q ∪ A = {a, b, 2, 3}
Q . A = {a2, a3, b2, b3}
Question
• Q= {a, b}, A = {2, 3}
• Find 2𝑄 𝑋 𝐴 (power set of Q x A)
Functions
• For nonempty sets A and B, a function f from a
set A to a set B, denoted by f: A → B, is an
association of each element of A with a unique
element of B.
A B
f: •
•
•
•
Functions (Cont.)
If A = {1, 2, 3, 4} and B = {a, b, c}, then f is a
function from A to B:
A B
1 a
f: 2 b
3 c
4
The function f can be written as:
f = {(1, c), (2, a), (3, b), (4, b)}
Functions (Cont.)
In other words, a function f is a binary relation
from A to B (any subset from A x B is a binary
relation) with the following property:
• for each a ∈ A, there is exactly one ordered
pair in f with the first component a.
Functions (Cont.)
We write b = f(a) when (a, b) ∈ f
• b is called the image of a under f
• A is called the domain of f
• B is called the codomain of f
• Range of f = { f(𝑥) : 𝑥∊ A } = f(A)
codomain
Example 1
Let A = {1,2,3,4} and B = {a, b, c}.
Then f = {(1, a), (2, a), (3,b ), (4, b)
is a function from A to B
Example 2
Let A = {1, 2, 3, 4} and B = {a, b, c}.
Then f = { (1, a), (2, a), (3, b), (3, c), (4, b) }
is NOT a function from A to B
There are 2 ordered pair: (3, b) and (3, c) with 3 as a first component
Example 3
Let A = {1, 2, 3, 4} and B = {a, b, c}.
Then g = { (1, a), (3, b ), (4, b) }
is NOT a function from A to B
why?
Example 4
f: Z → {0, 1} , where
0 if 𝑥 is even
f(𝑥) = ቊ
1 otherwise
{(p, 0), (p, 1), (q, 0), (q, 1), (r, 0), (r, 1)}
Question
• Let Q = {p, q, r} and ∑ = {0, 1}, Select a well-
defined function, f: Q x ∑ → Q:
1. f = { ((p, 0), p) , (( p, 1), q), ((p, 0), q), ((q, 1), q), ((r, 0), r),
((r, 1), r)}
2. f = { ((p, 0), p) , (( p, 1), q), ((q, 0), p), ((q, 1), q), ((q, 0), r),
((r, 1), q)}
3. f = { ((p, 0), p) , (( p, 1), p), ((q, 0), p), ((q, 1), p), ((r, 0), p),
((r, 1), p)}
Lecture Summary
• Alphabet.
• Strings and its properties.
• Formal languages and its properties.
• Operations of languages.
• Functions.