You are on page 1of 8

The Computational Model

According to Noam Chomsky, there are four types of grammars,


 Type 0
 Type 1
 Type 2
 Type 3.
The following table shows how they differ from each other −
Grammar
Grammar Accepted Language Accepted Automaton
Type
Type 0 Unrestricted grammar Recursively Enumerable Turing Machine
(RE) Language (TM)
Type 1 Context-Sensitive Context-Sensitive Linear-Bounded
Grammar (CSG) Language (CSL) Automaton
Type 2 Context-Free Grammar Context-Free Language PushDown
(CFG) (CFL) Automaton (PDA)
Type 3 Regular Grammar (RG) Regular Language (RL) Finite State
Automaton (FA)

Take a look at the following illustration. It shows the scope of each type of grammar
specified in Chomsky Hierarchy−

Type - 3 Grammar

Dr.C.Sathiya Kumar, VIT University Page 1


Type-3 grammars generate Regular Languages. It must have a single non-terminal on
the left-hand side and a right-hand side consisting of a single terminal or single terminal
followed by a single non-terminal.
The productions must be in the form,
X → a or X → aY
where X, Y ∈ N (Non terminal) and a ∈ T (Terminal)
The rule S → ε is allowed if S does not appear on the right side of any rule. S is the start
symbol.
Example
X→ε
X → a | aY
Y→b
Type - 2 Grammar
Type-2 grammars generate context-free languages.
The productions must be in the form,
A→γ
where A ∈ N (Non terminal) and γ ∈ (T ∪ N)* (String of terminals and non-
terminals).
These languages generated by these grammars are be recognized by a non-
deterministic pushdown automaton.
Example
S→Xa
X→a
X → aX
X → abc
X→ε
Type - 1 Grammar
Type-1 grammars generate context-sensitive languages.
The productions must be in the form
αAβ→αγβ
where A ∈ N (Non-terminal) and α, β, γ ∈ (T ∪ N)* (Strings of terminals and
non-terminals)
The strings α and β may be empty, but γ must be non-empty.

Dr.C.Sathiya Kumar, VIT University Page 2


The rule S → ε is allowed if S does not appear on the right side of any rule. S is the
start symbol. The languages generated by these grammars are recognized by a linear bounded
automaton.
Example
AB → AbBc
A → bcA
B→b
Type - 0 Grammar
Type-0 grammars generate recursively enumerable languages. The productions have
no restrictions. They are any phase structure grammar including all formal grammars. They
generate the languages that are recognized by a Turing machine.
The productions can be in the form of,
α→β
where α is a string of terminals and non-terminals with at least one non-terminal and
α cannot be null. β is a string of terminals and non-terminals.
Example
S → ACaB
Bc → acB
CB → DB
aD → Db
Theory of Computation
Theory of computation refers the computing performance of a program. Program is
a step by step expression of an algorithm. An algorithm gives the logical explanation of given
problem.
An algorithm is a recipe that produces output based on the given input.

x Algorithm f(x)

An Algorithm applies a function to ‘x’ and produces processed output.


Example: Prime (Number)
Prime(𝑥) → 𝑥 is a number
Which means that 𝑥 may be a prime or may not be.
𝑥 𝑖𝑠 𝑎 𝑝𝑟𝑖𝑚𝑒
𝑓(𝑥) = {
𝑥 𝑖𝑠 𝑛𝑜𝑡 𝑝𝑟𝑖𝑚𝑒

Dr.C.Sathiya Kumar, VIT University Page 3


Sets
There are different types of sets;
1. Empty set
2. Singleton set
3. Finite and Infinite set
4. Union of sets
5. Intersection of sets
6. Difference of sets
7. Subset of a set
8. Disjoint sets
9. Equality of two sets

1. Empty Set

A set that has no element should be called as Empty set. Another name for Empty set
could be Null set. Number of element in set X is represented as n(X). The empty set is
denoted as Φ. Thus, n(Φ) = 0. The cardinality of an empty set is zero since it has no element.

2. Singleton Set
A set that has one and only one element should be called as Singleton set. Sometimes,
it is known as unit set. The cardinality of singleton is one. If A is a singleton, then we can
express it as,

𝐴 = {𝑥 ∶ 𝑥 = 𝐴}

Example: Set A = {5} is a singleton set.

3. Finite and Infinite Set

A set that has predetermined number of elements or finite number of elements are said
to be Finite set. Like {1 ,2, 3, 4, 5, 6} is a finite set whose cardinality is 6, since it has 6
elements.
Otherwise, it is called as infinite set. It may be uncountable or countable. The union of
some infinite sets are infinite and the power set of any infinite set is infinite.

Examples:

1. Set of all the days in a week is a finite set.


2. Set of all integers is infinite set.

4. Union of Sets

Union of two or else most numbers of sets could be the set of all elements that
belongs to every element of all sets. In the union set of two sets, every element is written only
once even if they belong to both the sets. This is denoted as ‘∪’. If we have sets A and B,

Dr.C.Sathiya Kumar, VIT University Page 4


then the union of these two is 𝐴 ∪ 𝐵 and called as A union B. Mathematically, we can denote
it as,

𝐴 ∪ 𝐵 = {𝑥 ∶ 𝑥 ∈ 𝐴 𝑜𝑟 𝑥 ∈ 𝐵}.

The union of two sets is always commutative i.e. 𝐴 ∪ 𝐵 = 𝐵 ∪ 𝐴.

Example: 𝐴 = {1,2,3} and 𝐵 = {3,4,5} then 𝐴 ∪ 𝐵 = {1,2,3,4,5}

5. Intersection of Sets

It should be the set of elements that are common in both the sets. Intersection is
similar to grouping up the common elements. The symbol should be denoted as ‘∩’. If A and
B are two sets, then the intersection is denoted as A ∩ B and called as A intersection B and
mathematically, we can write it as,

𝐴 ∩ 𝐵 = {𝑥 ∶ 𝑥 ∈ 𝐴 𝑎𝑛𝑑 𝑥 ∈ 𝐵}

Example: 𝐴 = {1,2,3,4,5} and 𝐵 = {2,3,7} then 𝐴 ∩ 𝐵 = {2,3}

6. Difference of Sets

The difference of set A to B should be denoted as A - B. That is, the set of element that are in
set A not in set B is

𝐴 − 𝐵 = {𝑥 ∶ 𝑥 ∈ 𝐴 𝑎𝑛𝑑 𝑥 ∉ 𝐵}

and, B - A is the set of all elements of the set B which are in B but not in A i.e.

𝐵 − 𝐴 = {𝑥 ∶ 𝑥 ∈ 𝐵 𝑎𝑛𝑑 𝑥 ∉ 𝐴}

Example: 𝐴 = {1,2,3,4,5} and 𝐵 = {2,4,6,7,8}, then 𝐴 − 𝐵 = {1,3,5}

and 𝐵 − 𝐴 = {6,7,8}

7. Subset of a Set

In set theory, a set P is the subset of any set Q, if the set P is contained in set Q. It
means, all the elements of the set P also belong to the set Q. It is represented as '⊆’ or P ⊆ Q.

Example: 𝐴 = {1,2,3,4,5} and 𝐵 = {1,2,3,4,5,7,8}, then A is said to be a subset of B.


𝐴 ⊆ 𝐵.

Subset may be proper or improper. For example, if A = {1,3,5} then B = {1,5} is a


proper subset of A. The set C = {1,3,5} is a subset of A, but it is not a proper subset of A
since C=A. The set D={1,4} is not even a subset of A, since 4 is not an element of A.

Dr.C.Sathiya Kumar, VIT University Page 5


8. Disjoint Sets

If two sets A and B should have no common elements or we can say that the
intersection of any two sets A and B is the empty set, then these sets are known as disjoint
sets i.e. A ∩ B = ϕ. That means, when this condition n (A ∩ B) = 0 is true, then the sets are
disjoint sets.

Example:
𝐴 = {1,2,3} and 𝐵 = {4,5} then 𝑛(𝐴 ∩ 𝐵) = 0. Therefore, these sets A and B are disjoint
sets.

9. Equality of Two Sets

Two sets are said to be equal or identical to each other, if they contain the same elements.
When the sets P and Q is said to be equal, if P ⊆ Q and Q ⊆ P, then we will write as P = Q.

Examples:

1. If 𝐴 = {1,2,3} and 𝐵 = {1,2,3}, 𝑡ℎ𝑒𝑛 𝐴 = 𝐵.


2. Let 𝐴 = {𝑎, 𝑒, 𝑖, 𝑜, 𝑢} and 𝐵 = {𝑎, 𝑒, 𝑖, 𝑜, 𝑢, 𝑣} then 𝐴 ≠ 𝐵, since the set B has the
element v which is not in A.

Compiler

Compiler is a program that converts the given input into its equivalent output. Or
Convert the source language into its equivalent target language.

Input Output
Compiler

 Compiler is reading the source program character by character and forms tokens.
 Compiler scans the source program from left to right and finally accept the end of the
source program.
 Finally it produces the target program.
 In this, high language program instructions are converted into low level language
program instructions.

Dr.C.Sathiya Kumar, VIT University Page 6


Formal Language
A source program consists of a language called as a formal language. Formal
languages are designed by using Automaton or Automata theory.

Automata
The term "Automata" is derived from the Greek word "αὐτόματα" which means "self-
acting". An automaton (Automata in plural) is an abstract self-propelled computing device
which follows a predetermined sequence of operations automatically.
An automaton with a finite number of states is called a Finite Automaton (FA) or
Finite State Machine (FSM).
In 1930 Alan Turing studied an abstract machine that had all the capabilities like
todays computer. In 1940 and 1950 number of researchers studied about finite automata. In
late 1950, N.Chomsky began the study of formal grammars. In 1960, S.Cook extended Alan
Turing’s Study on abstract machines.

Mathematical Preliminaries and Notations


∑𝑚 is called the length of the input alphabet with input symbols.
Example:
∑0 = {𝜀} → 𝑙𝑒𝑛𝑔𝑡ℎ 𝑎𝑠 0
∑1 = {0,1} → 𝑙𝑒𝑛𝑔𝑡ℎ 𝑎𝑠 1
∑2 = {0,1,2} → 𝑙𝑒𝑛𝑔𝑡ℎ 𝑎𝑠 2
Then
∑∗ ⇒ 𝐾𝑙𝑛𝑒𝑒 𝐶𝑙𝑜𝑠𝑢𝑟𝑒 ⇒ {0,1,2,3, … , ∞}
∑+ ⇒ 𝐾𝑙𝑛𝑒𝑒 𝑃𝑙𝑢𝑠 ⇒ {1,2,3, … , ∞}
The mathematical preliminaries includes the following,
 Alphabets
 Strings
 Languages
Alphabet
An alphabet is any finite non empty set of symbols. It is denoted by ∑
Example: ∑ = {a, b, c, d} is an alphabet set where ‘a’, ‘b’, ‘c’, and ‘d’ are symbols with 4
elements

Dr.C.Sathiya Kumar, VIT University Page 7


String
A string or word over an alphabet set ∑ is a finite sequence of symbols.
Example: ∑ = {a, b} and the strings of the input symbols a, b is as follows,
∑ = {𝑎𝑏, 𝑏𝑎, 𝑎𝑎𝑏, 𝑏𝑎𝑏, 𝑎𝑏𝑎, 𝑎𝑏𝑏𝑎 … . . }
Operation on String
Length of string
Let ‘w’ be the string, and the length of the string denoted by |𝑤|, then the number of
symbols comparing with ‘w’ is more than one.
Example: w = abcab be the string, then the length of the string |𝑤| = 5
Empty or Null String
Consists of Null or zero input symbols. Denoted by 𝜀
Example: 𝑤 = 𝜀 𝑡ℎ𝑒𝑛 |𝑤| = 0.
Concatenation of String
The Concatenation of two strings ‘u’ and ‘v’ is a string obtained by appending
symbols of ‘v’ to the right end of ‘u’.
w = uv
Example:
𝑢 = 𝑎1 , 𝑎2 , 𝑎3 , … , 𝑎𝑛
𝑣 = 𝑏1 , 𝑏2 , 𝑏3 , … , 𝑏𝑚
w = uv
𝑤 = 𝑎1 , 𝑎2 , 𝑎3 , … , 𝑎𝑛 , 𝑏1 , 𝑏2 , 𝑏3 , … , 𝑏𝑚
Also 𝑤. 𝜀 = 𝜀. 𝑤 = 𝑤
Reverse of String

Dr.C.Sathiya Kumar, VIT University Page 8

You might also like