CS 501 TOC Lab Manual
CS 501 TOC Lab Manual
OBJECTIVE:
Design a Finite Automata for creating machine that accepts three consecutive one.
THEORY:
o Finite automata are used to recognize patterns.
o It takes the string of symbol as input and changes its state accordingly. When the
desired symbol is found, then the transition occurs.
o At the time of transition, the automata can either move to the next state or stay in the
same state.
o Finite automata have two states, Accept state or Reject state. When the input string
is processed successfully, and the automata reached its final state, then it will accept.
Q: finite set of states
∑: finite set of the input symbol
q0: initial state
F: final state
δ: Transition function
INPUT SET:
Here, Q is q0,q1,q2 and q3 set of states
∑ = {0,1} set of input symbols
q0 is initial state
q3 is the final state
δ: Transition function
Present state Next state for input 0 Next state for input 1
q0 q0 q1
q1 q0 q2
q2 q0 q3
q3 q3 q3
OUTPUT SET:
The strings that will be generated for this particular languages are 111, 0111, 1110, 01110,
0111.... in which 0 always appears in a clump of 3. The transition graph is as follows:
In a DFA, for a particular input character, the machine goes to one state only. A
transition function is defined on every state for every input symbol. Also in DFA
null (or ε) move is not allowed, i.e., DFA cannot change state without any input
character.
For example, below DFA with Σ = {0, 1} accepts all strings ending with 0.
One important thing to note is, there can be many possible DFAs for a pattern.
A DFA with a minimum number of states is generally preferred.
2) Nondeterministic Finite Automata(NFA): NFA is similar to DFA except
following additional features:
1. Null (or ε) move is allowed i.e., it can move forward without reading
symbols.
2. Ability to transmit to any number of states for a particular input.
However, these above features don’t add any power to NFA. If we compare both
in terms of power, both are equivalent.
Due to the above additional features, NFA has a different transition function, the
rest is the same as DFA.
δ: Transition Function
δ: Q X (Σ U ε ) --> 2 ^ Q.
As you can see in the transition function is for any input including null (or ε), NFA
can go to any state number of states. For example, below is an NFA for the above
problem.
NFA
One important thing to note is, in NFA, if any path for an input string leads to a
final state, then the input string is accepted. For example, in the above NFA,
there are multiple paths for the input string “00”. Since one of the paths leads to a
final state, “00” is accepted by the above NFA.
Some Important Points:
Justification:
Since all the tuples in DFA and NFA are the same except for one of the tuples,
which is Transition Function (δ)
In case of DFA
δ : Q X Σ --> Q
In case of NFA
δ : Q X Σ --> 2Q
Now if you observe you’ll find out Q X Σ –> Q is part of Q X Σ –> 2 Q.
On the RHS side, Q is the subset of 2 Q which indicates Q is contained in 2 Q or Q is
a part of 2Q, however, the reverse isn’t true. So mathematically, we can conclude
that every DFA is NFA but not vice-versa. Yet there is a way to convert an NFA
to DFA, so there exists an equivalent DFA for every NFA.
1. Both NFA and DFA have the same power and each NFA can be translated
into a DFA.
2. There can be multiple final states in both DFA and NFA.
3. NFA is more of a theoretical concept.
4. DFA is used in Lexical Analysis in Compiler.
5. If the number of states in the NFA is N then, its DFA can have maximum
2N number of states.
What are the applications of finite automata?
Automata is a machine that can accept the Strings of a Language L over an input
alphabet .
So far we are familiar with the Types of Automata . Now, let us discuss the
expressive power of Automata and further understand its Applications.
Expressive Power of various Automata :
The Expressive Power of any machine can be determined from the class or set of
Languages accepted by that particular type of Machine. Here is the increasing
sequence of expressive power of machines :
As we can observe that FA is less powerful than any other machine. It is important
to note that DFA and NFA are of same power because every NFA can be
converted into DFA and every DFA can be converted into NFA .
The Turing Machine i.e. TM is more powerful than any other machine.
(i) Finite Automata (FA) equivalence:
Finite Automata
≡ PDA with finite Stack
≡ TM with finite tape
≡ TM with unidirectional tape
≡ TM with read only tape
OBJECTIVE:
Design a Finite Automata for creating machine that accepts the string always ending with 101.
THEORY:
o Finite automata are used to recognize patterns.
o It takes the string of symbol as input and changes its state accordingly. When the
desired symbol is found, then the transition occurs.
o At the time of transition, the automata can either move to the next state or stay in the
same state.
o Finite automata have two states, Accept state or Reject state. When the input string
is processed successfully, and the automata reached its final state, then it will accept.
Q: finite set of states
∑: finite set of the input symbol
q0: initial state
F: final state
δ: Transition function
INPUT SET:
Here, Q is q0,q1,q2 and q3 set of states
∑ = {0,1} set of input symbols
q0 is initial state
q3 is the final state
δ: Transition function
Present state Next state for input 0 Next state for input 1
q0 q0 q1
q1 q2 q1
q2 q0 q3
q3 q2 q1
INPUT SET:
Basically we need to design an automata that accepts language containing strings which have
‘101’ as substring. This means that we can reach final state in DFA only when ‘101’ occur in
succession.
Where, q0 = Initial State
q3 = Final State
The smallest possible valid string is ‘101’ so from initial state q0, upon giving ‘101’ we should
reach final state q3.
If suppose any string starts with '0′ then we need the entire ‘101’ sequence to reach the final
state(to ensure ‘101’ is substring as given in question). Hence we will apply a self loop at state
q0 upon giving ‘0’ (transition into the same state q0).
If suppose at state q1, the input is ‘1’ i.e. string is of type ‘11’ then we only need ‘01’ sequence
to satisfy the criteria of ‘101’ substring. Hence we will apply self loop at state q1 upon giving
‘1’
If suppose at state q2, the input is ‘0’ i.e. string is of type ‘100’ then we need entire ‘101’
sequence to satisfy the criteria of ‘101’ as substring. Hence at state q2, upon giving ‘0’ we will
transition to state q0.
Finally at state q3, we have already reached by giving strings having ‘101’ as substring. Hence
for inputs ‘0’ and ‘1’ we will just self loop them (transition them to same state) and criteria will
still be fulfilled.
1. Q: finite set of states
2. ∑: finite set of the input symbol
3. q0: initial state
4. F: final state
5. δ: Transition function
Transition function can be defined as:
1. δ: Q x ∑→Q
OBJECTIVE:
Design a Finite Automata for Mode 3 Machine
THEORY:
o Finite automata are used to recognize patterns.
o It takes the string of symbol as input and changes its state accordingly. When the
desired symbol is found, then the transition occurs.
o At the time of transition, the automata can either move to the next state or stay in the
same state.
o Finite automata have two states, Accept state or Reject state. When the input string
is processed successfully, and the automata reached its final state, then it will accept.
Q: finite set of states
∑: finite set of the input symbol
q0: initial state
F: final state
δ: Transition function
INPUT SET:
Basically we need to design an automata that accepts language containing strings which have
‘mod 3’ . This means that we can reach final state in DFA only when ‘mod 3’ occur in
succession.
q0 = Final State
Present state Next state for input 0 Next state for input 1
q0 q0 q1
q1 q2
q0
q2
q1 q2
OUTPUT SET:
Basically we need to design an automata that accepts language containing strings which
have ‘mod 3’ . This means that we can reach final state in DFA only when ‘mod 3’ occur in
succession.
EXPECTED VIVA QUESTIONS:
For example, the expression "5 mod 2" would evaluate to 1, because 5 divided by 2 has
a quotient of 2 and a remainder of 1, while "9 mod 3" would evaluate to 0, because 9
divided by 3 has a quotient of 3 and a remainder of 0; there is nothing to subtract from 9
after multiplying 3 times 3.
When exactly one of a or n is negative, the naive definition breaks down, and
programming languages differ in how these values are defined.
A final state denotes the end of the execution flow of a state machine or region. It can
have multiple incoming transitions but no outgoing ones. Each region may contain at most
one final state. In the case of orthogonal regions, the execution flow stops when all
regions' final states have been reached.
Initial states are impossible to avoid, and follows from the definition of compound
states: For a compound state, whenever it becomes active, exactly one of its direct
children are also active. The “initial” state simply denotes which of the child states
become active when this happens.
Picking the right initial state can help decouple the various parts of the statechart. It
allows transitions to target the compound (parent) state instead of a child directly. This
allows collapsing the view of a compound state to see the bigger picture.
EXPERIMENT-4
Unit/Topic: 1/ Examples of Finite Automata
OBJECTIVE:
Design a C program for accepting decimal number divisible by 2
THEORY:
Attached
INPUT SET:
OUTPUT SET:
NAME OF FACULTY:
SIGNATURE:
DATE:
EXPERIMENT-5
Unit/Topic: 2/ DFA
OBJECTIVE:
Design a machine which accepts string having equal no. of 1’s and 0’s.
PROCEDURE:
Attached
INPUT SET:
OUTPUT SET:
NAME OF FACULTY:
SIGNATURE:
DATE:
EXPERIMENT-6
Unit/Topic: 2/ Regular Expression
OBJECTIVE:
Design a C program for creating a machine which count number of 1’s and 0’s in a given string.
THEORY:
Attached
INPUT SET:
OUTPUT SET:
NAME OF FACULTY:
SIGNATURE:
DATE:
EXPERIMENT-7
Unit/Topic: 2/Regular Expression
OBJECTIVE:
Design a C Program to find 2’s complement of a given binary number.
PROCEDURE:
Attached
INPUT SET:
OUTPUT SET
NAME OF FACULTY:
SIGNATURE:
DATE:
EXPERIMENT-8
Unit/Topic: 2/Regular Expression
OBJECTIVE:
Design a C Program which will increment the given binary number by 1.
PROCEDURE:
Attached
INPUT SET:
OUTPUT SET:
EXPERIMENT-9
Unit/Topic: 2/NDFA
OBJECTIVE:
Design a Program to convert NDFA to DFA.
PROCEDURE:
Attached
INPUT SET:
OUTPUT SET:
NAME OF FACULTY:
SIGNATURE:
DATE:
EXPERIMENT-10
Unit/Topic: 4/PDA
OBJECTIVE:
Design a PDA machine that accept the well-formed parenthesis.
PROCEDURE:
Attached
INPUT SET:
OUTPUT SET:
EXPECTED VIVA QUESTIONS:
1. What is PDA?
2. What are different types of PDA?
NAME OF FACULTY:
SIGNATURE:
DATE:
EXPERIMENT-11
Unit/Topic: 4/PDA
OBJECTIVE:
Design a PDA to accept WCWR where w is any string and WR is reverse of that string and C is a
Special symbol.
PROCEDURE:
Attached
INPUT SET:
OUTPUT SET:
NAME OF FACULTY
SIGNATURE:
DATE:
EXPERIMENT-12
Unit/Topic: 5/Turing Machine
OBJECTIVE:
n n n
Design a Turing machine that’s accepts a b c |n>=0
PROCEDURE:
Attached
INPUT SET:
OUTPUT SET: