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

1. Intro, Set, String, Language

Uploaded by

prasanna mishra
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)
4 views

1. Intro, Set, String, Language

Uploaded by

prasanna mishra
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/ 64

Theory of Computation (TOC)

Introduction of
TOC, Set, String and Language
Topics to be covered
 Looping
• Introduction to TOC
• Set
• Function
• Relation
• String
• Languages
Introduction to TOC
Introduction to TOC
 Automata theory (also known as Theory Of Computation) is a theoretical branch of Computer
Science and Mathematics, which mainly deals with the logic of computation with respect to
simple machines, referred to as automata.

 Automata* enables scientists to understand how machines compute functions and solve
problems.

 The main motivation behind developing Automata Theory was to develop methods to describe
and analyze the dynamic behavior of discrete systems.

 Automata originated from the word “Automaton” which is closely related to “Automation”.

Prof. Jay R Dhamsaniya #3130006 (PS)  Unit 1 – Basic Probability 4


Introduction to TOC (Cont..)
 Applications: It has following major uses:

 For digital circuit or VLSI Design or Sequential circuit design (as per requirement)
▪ To design digital circuit, TOC provides mathematical models that are used to design these circuits.

 It is very useful in Compiler design

 It is used in complexity theory and algorithm design

 It also has purpose for those problems which are not solvable, or its solution does not
exist.

Prof. Jay R Dhamsaniya #3130006 (PS)  Unit 1 – Basic Probability 5


Introduction to TOC (Cont..)
 Processor: It is a VLSI circuit.
Compiler Layer
(S/W layer): Same I/O
 Instruction Set: Holds the values on which
sequences of output will be generated.
 The processor works on some predefined instructions (It -5 V -5 V 0
has 70-75 instructions). 5v Processor 5V 1
Or
Input Digital Output
Chip
 Machine Language: The set of instructions
understood by the processor by which we can
communicate with the machine.

 Compiler Layer: It is used to communicate with the


processor.
 It works as a translator that converts one language to
another language (M/C language).

Prof. Jay R Dhamsaniya #3130006 (PS)  Unit 1 – Basic Probability 6


Set
Set
 A set is a collection of objects.
 The objects in a set are called elements of the set.
 Examples:
1. A = {11, 12, 21, 22} Roster Notation
2. B = {11, 12, 21, 11, 12, 22}
3. C = {x | x is odd integer greater than 1}
Set-builder Notation
4. D = {x | x Є B and x ≤ 11}

 B = {11, 12, 21, 11, 12, 22} is not normal, Set must contain distinct items.
 The Sets {10, 11, 12}, {11, 10, 12} and {12, 11, 10} are all equal.

 Formal Definition: Set is the unordered distinct items which has at least one common property.

 Empty Set: It is a set with no element. It represented with Φ= { }.

Prof. Jay R Dhamsaniya #3130006 (PS)  Unit 1 – Basic Probability 8


Operations on Sets
 Operations on the sets are:  The complement of a set A is the set A’ of everything that
is not an element of A from Universal Set U.
1. Complement
2. Union
3. Intersection 𝐴’ = {𝑥 ∈ 𝑈 | 𝑥 ∉ 𝐴}
4. Set Difference
5. Symmetric Difference U
6. Cartesian product A

 Example:
U = {1,2,3,4,5}
A = {1,2}
A’ = {3,4,5}

Prof. Jay R Dhamsaniya #3130006 (PS)  Unit 1 – Basic Probability 9


Operations on Sets
 Operations on the sets are:  The Union (𝐴 𝑈 𝐵) is a collection of all distinct elements
1. Complement from both the set A and B.
2. Union
3. Intersection 𝐴 𝑈 𝐵 = {𝑥 | 𝑥 ∈ 𝐴 𝑜𝑟 𝑥 ∈ 𝐵}
4. Set Difference
U
5. Symmetric Difference
𝐴 𝐵
6. Cartesian product

 Example:
A = {1, 3, 5, 7, 9}
B = {1, 2, 3, 4, 5}
A U B = {1, 2, 3, 4, 5, 7, 9}

Prof. Jay R Dhamsaniya #3130006 (PS)  Unit 1 – Basic Probability 10


Operations on Sets
 Operations on the sets are:  The intersection A ∩ B of two sets A and B is the set that
contains all elements of A that also belong to B, but no
1. Complement
other elements.
2. Union
3. Intersection 𝐴 ∩ 𝐵 = {𝑥 | 𝑥 ∈ 𝐴 𝑎𝑛𝑑 𝑥 ∈ 𝐵}
4. Set Difference
5. Symmetric Difference U
6. Cartesian product 𝐴 𝐵

 Example:
A = {1, 3, 5, 7, 9}
B = {1, 2, 3, 4, 5}
A ∩ B = {1, 3, 5}
Prof. Jay R Dhamsaniya #3130006 (PS)  Unit 1 – Basic Probability 11
Operations on Sets
 Operations on the sets are:  The set difference A - B of two sets A and B is the set of
everything in A but not in B.
1. Complement
2. Union
𝐴 – 𝐵 = {𝑥 | 𝑥 ∈ 𝐴 𝑎𝑛𝑑 𝑥 ∉ 𝐵}
3. Intersection = {𝑥 | 𝑥 ∈ 𝐴} ∩ {𝑥 | 𝑥 ∉ 𝐵}
4. Set Difference = 𝐴 ∩ 𝐵’
5. Symmetric Difference
6. Cartesian product U
𝐴 𝐵

 Example:
A = {1, 3, 5, 7, 9}
B = {1, 2, 3, 4, 5}
A - B = {7, 9}
Prof. Jay R Dhamsaniya #3130006 (PS)  Unit 1 – Basic Probability 12
Operations on Sets
 Operations on the sets are:  The symmetric difference A ⊖ B of two sets A and B is
the set of everything in A but not in B or the set of
1. Complement
everything in B but not in A.
2. Union
3. Intersection
4. Set Difference 𝐴 ⊖ 𝐵 = (𝐴 – 𝐵) 𝑈 (𝐵 – 𝐴)
5. Symmetric Difference
6. Cartesian product U

 Example:
A = {1, 3, 5, 7, 9}
B = {1, 2, 3, 4, 5}
A ⊖ B = {7, 9, 2, 4}
Prof. Jay R Dhamsaniya #3130006 (PS)  Unit 1 – Basic Probability 13
Operations on Sets
 Operations on the sets are:  The Cartesian product A x B of two sets A and B is the set
of all ordered pairs (a, b) where a ∈ A and b ∈ B.
1. Complement
2. Union
3. Intersection 𝐴𝑥𝐵 = 𝑎, 𝑏 𝑎 ∈ 𝐴 𝑎𝑛𝑑 𝑏 ∈ 𝐵}
4. Set Difference
5. Symmetric Difference  Example:
6. Cartesian product A = {1, 3, 5}
B = {2, 4}
A x B = {(1,2), (1,4), (3,2), (3,4), (5,2), (5,4)}

Prof. Jay R Dhamsaniya #3130006 (PS)  Unit 1 – Basic Probability 14


Other Operations on Set
 Operations on the sets are:  The Cardinality of set A is the total number of elements in A.
1. Cardinality of Set
2. Subset 𝐴 = 𝑛 𝑛 𝑖𝑠 𝑛𝑢𝑚𝑏𝑒𝑟 𝑜𝑓 𝑒𝑙𝑒𝑚𝑒𝑛𝑡𝑠 𝑖𝑛 A}
3. Proper Subset
4. Power Set  Example:
A = {1, 3, 5}
B = {2, 4}
|A| = 3 and |B| =2

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


|A x B| = 6

|Φ| = |{ }| = 0

Prof. Jay R Dhamsaniya #3130006 (PS)  Unit 1 – Basic Probability 15


Other Operations on Set
 Operations on the sets are:  The subset of set A is the set of element(s) of A.
1. Cardinality of Set  It is a unary operation.
2. Subset
𝑆𝑢𝑏𝑠𝑒𝑡 𝑜𝑓 𝐴 = {𝑥 | 𝑥 ∈ 𝐴}
3. Proper Subset
4. Power Set  Example:
A = {1, 3, 5}
Subsets of A = Φ, {1}, {3}, {5}, {1,3}, {1,5}, {3,5}, {1,3,5}
➢ 𝛷 or empty set is the subset of each and every set.
➢ Every set is a subset of itself.

➢ Total no. of subset of a set of length n?


➢ = 2n
➢ Total no. of non null subsets of a set of length n = 2n - 1

Prof. Jay R Dhamsaniya #3130006 (PS)  Unit 1 – Basic Probability 16


Other Operations on Set
 Operations on the sets are:  The proper subset of set A is the set of element(s) of A
excluding itself.
1. Cardinality of Set
2. Subset 𝑆𝑢𝑏𝑠𝑒𝑡 𝑜𝑓 𝐴 = 𝑥 𝑥 ∈ 𝐴, 𝑎𝑛𝑑 𝑥 ≠ 𝐴}
3. Proper Subset  Example:
4. Power Set A = {1, 3, 5}
Proper Subsets of A = Φ, {1}, {3}, {5}, {1,3}, {1,5}, {3,5}

➢ 𝛷 or empty set is included in proper subset.


➢ A set cannot be a proper subset of itself

➢ Total no. of proper subsets of a set of length n?


➢ = 2n - 1
➢ Total no. of non null proper subsets of a set of length n = 2n - 2

Prof. Jay R Dhamsaniya #3130006 (PS)  Unit 1 – Basic Probability 17


Other Operations on Set
 Operations on the sets are:  The Power Set of set A is the set of all subset of A.
1. Cardinality of Set  It is a unary operation.
2. Subset/Proper Subset
𝑃 𝐴 𝑜𝑟 2𝐴 = 𝑎, 𝑏, . . 𝑎 ∈ 𝐴, 𝑏 ∈ 𝐴, . . }
3. Power Set

 Example:
A = {1, 3, 5}
B = {2, 4}
P(A) = {Φ, {1}, {3}, {5}, {1,3}, {1,5}, {3,5}, {1,3,5} }

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


|P(A x B)| = 26
➢ 𝛷 is the subset of each and every set.

Prof. Jay R Dhamsaniya #3130006 (PS)  Unit 1 – Basic Probability 18


Set of identities
 Commutative laws
𝐴∩𝐵 = 𝐵∩𝐴
𝐴𝑈𝐵 = 𝐵𝑈𝐴

 Associative laws

𝐴 ∩ (𝐵 ∩ 𝐶) = (𝐴 ∩ 𝐵) ∩ 𝐶
𝐴 𝑈 (𝐵 𝑈 𝐶) = (𝐴 𝑈 𝐵) 𝑈 𝐶

 Distributive laws

𝐴 𝑈 (𝐵 ∩ 𝐶) = (𝐴 𝑈 𝐵) ∩ (𝐴 𝑈 𝐶)
𝐴 ∩ (𝐵 𝑈 𝐶) = (𝐴 ∩ 𝐵) 𝑈 (𝐴 ∩ 𝐶)

Prof. Jay R Dhamsaniya #3130006 (PS)  Unit 1 – Basic Probability 19


Set of identities
 Idempotent laws
𝐴𝑈𝐴 = 𝐴
𝐴∩𝐴 = 𝐴

 Absorptive laws

𝐴 𝑈 (𝐴 ∩ 𝐵) = 𝐴
𝐴 ∩ (𝐴 𝑈 𝐵) = 𝐴

 De Morgan laws

(𝐴 𝑈 𝐵)’ = 𝐴’ ∩ 𝐵’
(𝐴 ∩ 𝐵)’ = 𝐴’ 𝑈 𝐵’

Prof. Jay R Dhamsaniya #3130006 (PS)  Unit 1 – Basic Probability 20


Set of identities
 Other complements laws
(𝐴’)’ = 𝐴
𝐴 ∩ 𝐴’ = Φ
𝐴 𝑈 𝐴’ = 𝑈
 Other empty set laws

𝐴𝑈Φ = 𝐴
𝐴∩Φ = Φ

 Other universal set laws

𝐴𝑈𝑈 = 𝑈
𝐴∩𝑈 = 𝐴

Prof. Jay R Dhamsaniya #3130006 (PS)  Unit 1 – Basic Probability 21


Functions
Functions
 Domain: What can go into the function is called domain.
 Codomain: What may possibly come out from a function is codomain.
 Range: What actually come out from a function is range. The range of function is subset of
codomain
A B
 Example:
𝒇: 𝑵→𝑵, 𝒇(𝒙) = 𝟐𝒙 + 𝟏 1
1 2
f(1)=2(1)+1= 3 2
3
4
f(2)=2(2)+1= 5 3
5
Range 6
f(3)=2(3)+1= 7 4
7
8
f(4)=2(4)+1= 9 9
10
 The range of function f(x) = {3, 5, 7, 9} Domain Codomain

Prof. Jay R Dhamsaniya #3130006 (PS)  Unit 1 – Basic Probability 23


Onto Function
 If the range of function and codomain of function are equal or every element of the codomain is
actually one of the values of the function, then function is said to be onto or surjective or
surjection.
 Example: 𝒇 ∶ 𝑨 → 𝑩, 𝒇 𝒙 = 𝒙𝟐 where,
A B
A = {-2,-1,1,2,3,4} and B = {1,4,9,16} -2
1
-1
f(-2) = 4
1 4
f(-1) = 1
2
f(1) = 1 9
3
f(2) = 4 16
4
f(3) = 9
f(4) = 16
 The range of function f(A) = {1, 4, 9, 16} = B
Prof. Jay R Dhamsaniya #3130006 (PS)  Unit 1 – Basic Probability 24
One-to-One Function
 A function for which every element of the range of the function corresponds to
exactly one element of the domain is known as One-to-One or injective or injection.
 Example: 𝒇 ∶ 𝑨 → 𝑩, 𝒇 𝒙 = 𝒙𝟐 where,
A = {1,2,3,4} and B = {1,4,9,16,25,36} A B
1 1

f(1) = 1 2 4

f(2) = 4 9
3
f(3) = 9
16
4
f(4) = 16
25

36

Prof. Jay R Dhamsaniya #3130006 (PS)  Unit 1 – Basic Probability 25


Bijection Function
 If function is both one-to-one and onto then function is called Bijection function.
 Example: 𝒇 ∶ 𝑨 → 𝑩, 𝒇 𝒙 = 𝒙𝟐 where,
A = {1,2,3,4} and B = {1,4,9,16} A B
f(1) = 1
1 1
f(2) = 4
4
f(3) = 9 2
f(4) = 16 3
9

16
4

Prof. Jay R Dhamsaniya #3130006 (PS)  Unit 1 – Basic Probability 26


Prove that f: R → R, f(x) = x2 is not one-to-one and not onto function
 The range and codomain of 𝑓(𝑥) = 𝑥2 are not equal, So function 𝑓 is not onto function.
 The function is not one to one because elements of 𝐵 are connected with more than one
elements of 𝐴.
f(-2) = 4 A B
f(-1) = 1 -2.0 -2.0
f(1) = 1 -1.0 -1.0
f(2) = 4 1.0 1.0
f(3) = 9 2.0 4.0
f(4) = 16 3.0 9.0
16.0
4.0

Prof. Jay R Dhamsaniya #3130006 (PS)  Unit 1 – Basic Probability 27


Prove that f: R → R+, f(x) = x2 is not one-to-one and onto function
 The range and codomain of 𝑓(𝑥) = 𝑥2 are equal So, function 𝑓 is onto function.
 The function is not one to one because elements of 𝐵 are connected with more than one
elements of 𝐴.
f(-2) = 4 A B
f(-1) = 1 -2.0
f(1) = 1 -1.0
f(2) = 4 1.0 1.0
f(3) = 9 2.0 4.0
f(4) = 16 3.0 9.0
16.0
4.0

Prof. Jay R Dhamsaniya #3130006 (PS)  Unit 1 – Basic Probability 28


Prove that f: R+ → R, f(x) = x2 is one-to-one and not onto function
 The range and codomain of 𝑓(𝑥) = 𝑥2 are not equal So, function 𝑓 is not onto function.
 The function is one to one because elements of 𝐵 are connected with single element of 𝐴.
f(1) = 1
f(2) = 4
A B
f(3) = 9
f(4) = 16 -2.0
-1.0
1.0 1.0
2.0 4.0
3.0 9.0
16.0
4.0

Prof. Jay R Dhamsaniya #3130006 (PS)  Unit 1 – Basic Probability 29


Prove that f: R+ → R+, f(x) = x2 is one-to-one and onto function (bijection)
 The range and codomain of 𝑓(𝑥) = 𝑥2 are equal So, function 𝑓 is onto function.
 The function is one to one because elements of 𝐵 are connected with single element of 𝐴.
 The function 𝑓(𝑥) = 𝑥2 is onto function as well as one-to-one function. So, it is called as
bijection function.
f(1) = 1 B
A
f(2) = 4
f(3) = 9 1.0 1.0
f(4) = 16
2.0 4.0
3.0 9.0
16.0
4.0

Prof. Jay R Dhamsaniya #3130006 (PS)  Unit 1 – Basic Probability 30


Compositions of Function
 Let 𝑓 ∶ 𝐴 → 𝐵 and 𝑔 ∶ 𝐵1 → 𝐶, the range of f is a subset of B1, then 𝑔 𝑓 𝑥 makes sense for
each 𝑥 ∈ 𝐴 and the function ℎ ∶ 𝐴 → 𝐶 defined by ℎ 𝑥 = 𝑔 𝑓 𝑥 is called the composition
of 𝑔 and 𝑓.
 It is written as ℎ = 𝑔 ∘ 𝑓
f g
 Example:
 ℎ 𝑐 =𝑔 𝑓 𝑥 =#
A B B1 C

a 1 @
b 2 #
c 3 !

d 4

Prof. Jay R Dhamsaniya #3130006 (PS)  Unit 1 – Basic Probability 31


Inverse of Function
 Let 𝑓 be a function whose domain is the set 𝑋, and whose range is the set 𝑌. Then 𝑓 is
invertible if there exists a function 𝑔 with domain 𝑌 and range 𝑋, with the property:
𝑓 𝑥 =𝑦 ⇔𝑔 𝑦 =𝑥
 To be invertible a function must be both an injection and a surjection.
 Example:

A B A B
a 1 1 a

b 2 f 2 b
f-1
c 3 3 c

d 4 4 d

Prof. Jay R Dhamsaniya #3130006 (PS)  Unit 1 – Basic Probability 32


Relations
Relations
 A relation on a set A is defined as subset of 𝐴 × 𝐴.
 The relation 𝑅 is denoted as aRb where 𝑎, 𝑏 𝜖 𝐴 and pair (𝑎, 𝑏) 𝜖 𝑅.
 Example:
𝑁 = {1,2,3}
𝑁 × 𝑁 = {(1,1), (1,2), (1,3), (2,1), (2,2), (2,3), (3,1), (3,2), (3,3)}

 Relation is a set of ordered pairs.

 The ‘=‘ relation on 𝑁 × 𝑁 is : {(1,1), (2,2), (3,3)}


where
1=1
2=2
3=3

Prof. Jay R Dhamsaniya #3130006 (PS)  Unit 1 – Basic Probability 34


Types of Relations
1. R is reflexive if for every x ϵ A, 𝑥𝑅𝑥, (where it is applicable)
Example: A = {a, b, c}, R ⊆ A X A.

R1 = {(a, b), (a, a), (b, b) }…?

1. R is irreflexive if for every x ϵ A, 𝑥𝑅𝑥

2. R is symmetric if for every x and y in A, if 𝑥𝑅𝑦, then there must be 𝑦𝑅𝑥.

Prof. Jay R Dhamsaniya #3130006 (PS)  Unit 1 – Basic Probability 35


Types of Relations

4. R is antisymmetric if for every x and y in A, if 𝑥𝑅𝑦, then there must be 𝑦𝑅𝑥 until
unless x =y.

5. R is transitive if for every x, y and z in A, if 𝑥𝑅𝑦 and 𝑦𝑅𝑧, then 𝑥𝑅𝑧.

Prof. Jay R Dhamsaniya #3130006 (PS)  Unit 1 – Basic Probability 36


Properties of Equivalence Relations
 Assume that 𝑅 is a relation on a set 𝐴, in other words, 𝑅 ⊆ 𝐴 × 𝐴, where (𝑥, 𝑦) 𝜖 𝑅 to indicate
𝑥 is related to 𝑦 via Relation 𝑅.

1. R is reflexive if for every x ϵ A, 𝑥𝑅𝑥

2. R is symmetric if for every x and y in A, if 𝑥𝑅𝑦, then 𝑦𝑅𝑥

3. R is transitive if for every x, y and z in A, if 𝑥𝑅𝑦 and 𝑦𝑅𝑧, then 𝑥𝑅𝑧.

4. R is an equivalence relation on A, if R is reflexive, symmetric and transitive.

Prof. Jay R Dhamsaniya #3130006 (PS)  Unit 1 – Basic Probability 37


Example: Equivalence Relation
 A={a, b}, R={(a, a), (b, b), (a, b), (b, a)}

 Reflexive: {(a, a),(b, b)}


 Symmetric: {(a, b), (b, a)}
 Transitive: {(a, a), (a, b), (a, b)
(b, b), (b, a), (b, a)
(a, b), (b, b), (a, b)
(a, b), (b, a), (a, a)
(b, a), (a, b), (b, b)
(b, a), (a, a), (b, a)}

 Above relation is Equivalence relation because it is Reflexive, symmetric and transitive.

Prof. Jay R Dhamsaniya #3130006 (PS)  Unit 1 – Basic Probability 38


Exercise
1. A={1, 2, 3}, R={(1, 2), (1, 1), (2, 1), (2, 2), (3, 2), (3, 3)} is equivalent relation?

2. A={1, 2, 3, 4}, R={(1, 1), (2, 2), (2, 3), (3, 2), (4, 2), (4, 4)} is equivalent relation?

3. A={0, 1, 2}, R={(0, 0), (1, 1), (2, 2), (1, 0), (2, 1)} is equivalent relation?

Prof. Jay R Dhamsaniya #3130006 (PS)  Unit 1 – Basic Probability 39


String
String
 String: It is a sequence of symbols/alphabets.
 Symbol: A symbol (often also called a character) is the smallest building block, which can be
any alphabet, letter, or picture.
 Example: a, b, c, 0, 1,….

 Alphabets (Σ): Alphabets are a set (nonempty) of symbols, which are always finite.
 Example:
 Σ = {0, 1} is an alphabet of binary digits.
 Σ = {0, 1, 2, 3..9} is an alphabet of decimal digits.
 Σ = {a, b, c..}
 Σ = {A, B, C…}

 String: It is a finite sequence of symbols over the given alphabets.


 Note: Empty string is the string with zero occurrence of symbols, represented as ε.

Prof. Jay R Dhamsaniya #3130006 (PS)  Unit 1 – Basic Probability 41


String: Example
 String: It is a finite sequence of symbols over the given alphabets.
 Example:
 u = abc
 v = bca
 w = aab
 A string is generally denoted as w and the length of a string is denoted as |w|.
 For above strings, the length of u, v, w is, |u|=|v|=|w| = 3.

 Null String: String that doesn't contain any element or string whose length is 0.

 Null string is represented by ‘ε’ (epsilon).


 |ε| = 0

Prof. Jay R Dhamsaniya #3130006 (PS)  Unit 1 – Basic Probability 42


String (Cont..)
Number of Strings (of length 2) that can be generated over the alphabet {a, b}:
--
aa
ab
ba
bb

➢ Length of String |w| = 2, Number of Strings = 4

➢ Conclusion: For alphabet {a, b} with length n, number of strings can be generated = 2n.

 Note: If the number of symbols in the alphabet Σ is represented by |Σ|, then a number of strings of length n,
possible over Σ is |Σ|n.

Prof. Jay R Dhamsaniya #3130006 (PS)  Unit 1 – Basic Probability 43


Operations on Strings
 Operations on the Strings are:
1. Length of String
2. Concatenation of Strings
3. Reverse of String
4. Sub String
5. Power of String
6. Prefix of String
7. Suffix of String

Prof. Jay R Dhamsaniya #3130006 (PS)  Unit 1 – Basic Probability 44


Operations on Strings
 Operations on the Strings are:  The length of a string w is the number of elements
symbols in the string w.
1. Length of String
2. Concatenation of Strings
𝑤 = 𝑛 𝑛 𝑖𝑠 𝑛𝑢𝑚𝑏𝑒𝑟 𝑜𝑓 𝑒𝑙𝑒𝑚𝑒𝑛𝑡𝑠 𝑖𝑛 w}
3. Reverse of String
4. Sub String
5. Power of String  Example:
6. Prefix of String u = abc
7. Suffix of String |u| = 3
v=ε
|v| = 0

Prof. Jay R Dhamsaniya #3130006 (PS)  Unit 1 – Basic Probability 45


Operations on Strings
 Operations on the Strings are:  Concatenation of two strings w and p is the string z which
appends the string p after w.
1. Length of String
2. Concatenation of Strings
z = 𝑤. 𝑝
3. Reverse of String
4. Sub String  Example: Concatenation of two strings is not commutative.
w.p ≠ p.w
5. Power of String w = abc abcaab ≠ aababc
6. Prefix of String P = aab
Both are different strings
7. Suffix of String z = w.p = abcaab
|z| = |w| + |p| = 6

w.ε = w (ε does not contain any element)


ε.ε.ε = ε
ε.w.ε = w

Prof. Jay R Dhamsaniya #3130006 (PS)  Unit 1 – Basic Probability 46


Operations on Strings
 Operations on the Strings are:  Reverse of two strings w is the string w’ that is reverse of
w.
1. Length of String
2. Concatenation of Strings
w ′ = 𝑟𝑒𝑣𝑒𝑟𝑠𝑒 𝑜𝑓 𝑤
3. Reverse of String
4. Sub String  Example:
5. Power of String w = abc
6. Prefix of String w’ = cba
7. Suffix of String

Prof. Jay R Dhamsaniya #3130006 (PS)  Unit 1 – Basic Probability 47


Operations on Strings
 Operations on the Strings are:  Substrings are the sub sequences (s) of the string w.
1. Length of String
2. Concatenation of Strings s= 𝑠𝑢𝑏 𝑠𝑒𝑞𝑢𝑛𝑐𝑒𝑠 𝑜𝑓 𝑤
3. Reverse of String
 Example:
4. Substrings w = abc
5. Power of String Substrings of w = ε, a, b, c, ab, bc, abc.
6. Prefix of String
7. Suffix of String ε is the substring of each and every string.

➢ Total No of substrings for a string of length 5 with distinct


symbols:
= 16

Prof. Jay R Dhamsaniya #3130006 (PS)  Unit 1 – Basic Probability 48


Operations on Strings
 Operations on the Strings are:  The n power of string s is the string computed by
concatenating s with ε, n times.
1. Length of String
2. Concatenation of Strings
Power of sn = 𝑠. 𝑠. 𝑠 … . . 𝑠 (𝑛 𝑡𝑖𝑚𝑒𝑠)
3. Reverse of String
4. Substrings  Example:
5. Power of String s = 11
6. Prefix of String s0 = ε
7. Suffix of String s1 = (11)1 = 11
s2 = (11)2 = 11.11= 1111
s3 = (11)3 = 11.11.11= 111111

Prof. Jay R Dhamsaniya #3130006 (PS)  Unit 1 – Basic Probability 49


Operations on Strings
 Operations on the Strings are:  Prefix of string s are the substrings preceeded in s.
1. Length of String
2. Concatenation of Strings  Example:
3. Reverse of String s = abcde
4. Substrings Prefix of s = ε, a, ab, abc, abcd, abcde.
5. Power of String
6. Prefix of String
7. Suffix of String ➢ For a string of length l of distinct symbol, how many
prefix are there?
➢ = l+1

Prof. Jay R Dhamsaniya #3130006 (PS)  Unit 1 – Basic Probability 50


Operations on Strings
 Operations on the Strings are:  Suffix of string s are the substrings succeeded in s.
1. Length of String  Example:
2. Concatenation of Strings s = abcde
3. Reverse of String Suffix of s = ε, e, de, cde, bcde, abcde.
4. Substrings
5. Power of String ➢ For a string of length l of distinct symbol, how many
6. Prefix of String suffix are there?
➢ = l+1
7. Suffix of String

Note: For a string of length l with same symbols, the prefix


and suffix are same.
Example: “aaa”,
Prefix/Suffix are: ε, a, aa, aaa.

Prof. Jay R Dhamsaniya #3130006 (PS)  Unit 1 – Basic Probability 51


Exercises:
1. Consider a string of length n of distinct symbols, calculate total number of substrings.

Ans. = (1+ n(n+1)/2)

2. Consider a string of length n of same symbols, how many distinct substrings are there?

Ans. = n+1 (Note: If word distinct is not describe, then assume it.)

Prof. Jay R Dhamsaniya #3130006 (PS)  Unit 1 – Basic Probability 52


Exercises:
1. Consider a string of length n of distinct symbols, calculate total number of proper/non-null
substrings.

Ans. = n(n+1)/2

2. Consider a string of length n of distinct symbols, how many total no. of non null and proper
substrings are there?

Ans. = Ans. = n(n+1)/2-1

Prof. Jay R Dhamsaniya #3130006 (PS)  Unit 1 – Basic Probability 53


Exercises:
1. Consider a string of length n of distinct symbols, how many minimum prefix and suffix will be
same?

Ans. = 2

2. Consider a string of length n of same symbols, how many prefix and suffix will be same?

Ans. = l+1

Prof. Jay R Dhamsaniya #3130006 (PS)  Unit 1 – Basic Probability 54


Languages
Closure Representation
 L+: It is a Positive Closure that represents a set of all strings except Null or ε-strings.
 L*: It is Kleene Closure, that represents the occurrence of certain alphabets for given language
alphabets from zero to the infinite number of times. In which ε-string is also included.

 From the above two statements, it can be concluded that: L* = {ε} U L+

 Example:
 Language accepting all combination of g's over Σ={g}:
g* = {ε, g, gg, ggg, gggg, ggggg,...}

 Language accepting all combination of g's over Σ={g} excluding ε:


g+ = {g, gg, ggg, gggg, ggggg, gggggg,...}

56
Closure Representation
 Note: Σ* is a set of all possible strings (often power set (need not be unique here or we can
say multiset) of string).
 So, this implies that language is a subset of Σ*. This is also called a “Kleene Star”.
 Kleene Star is also called a “Kleene Operator” or “Kleene Closure”.

 Engineers and IT professionals make use of Kleene Star to achieve all set of strings which is
to be included from a given set of characters or symbols. It is one kind of Unary operator.

 In Kleene Star methodology all individual elements of a given string must be present but
additional elements or combinations of these alphabets can be included to any extent.
Example: Input String: “GFG".
Σ* = { ε, “GFG", "GGFG", "GGFG", "GFGGGGGGGG", "GGGGGGGGFFFFFFFFFGGGGGGGG", ...}
(Kleene Star is an infinite set but if we provide any grammar rules then it can work as a finite set. Please note
that we can include ε string also in given Kleene star representation.)

57
Language
 A set of strings all of which are chosen from some 𝛴 ∗ , where 𝛴 is a particular alphabet, is
called a language.
 If 𝛴 is an alphabet, and 𝐿 ⊆ 𝛴 ∗ , then 𝐿 is said to be language over alphabet 𝛴.
 Language comprises of:
 Set of characters – 𝛴
 Set of strings (words) defined from set of character - 𝛴 ∗
 Language L is defined from 𝛴 ∗ , and 𝐿 ⊆ 𝛴 ∗ because 𝛴 ∗ contains many string which may
not satisfy the rules of language.
 Example:
 𝛴 = {a, b}
 𝛴 ∗ = {ε, a, b, aa, ab, ba, bb, aaa, aab, aba, abb, baa, …}

58
Language (Cont..)
 A language that can be formed over ‘Σ’ can be Finite or Infinite.

 Example of Finite Language:

 L1 = { set of string of 2 }

 L1 = { xy, yx, xx, yy }

 Example of Infinite Language:

 L1 = { set of all strings starts with 'b’ }

 L1 = { babb, baa, ba, bbb, baab, ....... }

59
Operations over Language
 Operations over the language are:
1. Concatenation
2. Union
3. * (Kleene closure)
4. +

If 𝐿1 , 𝐿2 ⊆ 𝛴 ∗ then concatenation is defined as


𝐿1𝐿2 = 𝑥𝑦 𝑥 𝜖 𝐿1 𝑎𝑛𝑑 𝑦 𝜖 𝐿2}
Example:
𝐿1 = {hope, fear} and 𝐿2 = {less, fully}

hopeless

𝐿1𝐿2 = {hopeless, hopefully, fearless, fearfully}


Prof. Jay R Dhamsaniya #3130006 (PS)  Unit 1 – Basic Probability 60
Operations over Language
 Operations over the language are:
1. Concatenation
2. Union
3. * (Kleene closure)
4. +

If 𝐿1 , 𝐿2 ⊆ 𝛴 ∗ then union is defined as


𝐿1 | 𝐿2 = 𝑥 𝑥 𝜖 𝐿1 𝑜𝑟 𝑥 𝜖 𝐿2}
Example:
𝐿1 = {hope, fear} and 𝐿2 = {less, fully}

𝐿1 | 𝐿2 = {hope, fear, less, fully}

Prof. Jay R Dhamsaniya #3130006 (PS)  Unit 1 – Basic Probability 61


Operations over Language
 Operations over the language are:
1. Concatenation
2. Union
3. * (Kleene closure)
4. +

If 𝐿 is a set of words then by 𝐿∗ we mean the set of all finite strings formed by concatenating
words from S, where any word may be used as often, we like, and where the null string is also
included. ∞

𝐿∗ = ራ 𝐿𝑖
𝑖=0
Example: 𝐿 = {ab}

𝐿* = {ε, ab, abab, ababab, abababab, ….}


Prof. Jay R Dhamsaniya #3130006 (PS)  Unit 1 – Basic Probability 62
Operations over Language
 Operations over the language are:
1. Concatenation
2. Union
3. * (Kleene closure)
4. +

If 𝐿 is a set of words then by 𝐿+ we mean the set of all finite strings formed by concatenating
words from L, where any word may be used as often, we like, and where the null string is not
included. ∞

𝐿+ = ራ 𝐿𝑖
𝑖=1
Example: 𝐿 = {ab}

𝐿+ = {ab, abab, ababab, abababab, ….}


Prof. Jay R Dhamsaniya #3130006 (PS)  Unit 1 – Basic Probability 63
Thank You

You might also like