Vous êtes sur la page 1sur 14



Name:Tanupriya Chaubey
Roll No:049

Finite State Automata

A finite-state automaton is a device that can be in one of a finite number of states . In certain
conditions, it can switch to another state. This is called atransition . When the automaton
starts working (when it is switched on), it can be in one of its initial states. There is also
another important subset of states of the automaton: the final states. If the automaton is in a
final state when it stops working, it is said to accept its input. The input is a sequence of
symbols. The interpretation of the symbols depends on the application
It is convenient to present automata as directed graphs. The vertices denote states.
They are portrayed as small circles. The transitions form the edges - arcs with arrows
pointing from the source state (the state where the transition originates) to the target state.
They are labeled with symbols. Unless it is clear from the context, the initial states have short
arrows that point to them from ``nowhere''. The final states are represented as two concentric

The example automaton (fig. 2.1) contains 6 states labeled A, B, C, D, E and F. The state
labeled A is initial. The states A, C, and D are final. The automaton contains no cycles, as it is
impossible to leave a state, follow some transitions, and return in this way to the same
original state.
Finite State Automata (Finite State Machines)
Finite State Automata are graphs in which the vertices represent the states of an
object (or system).
one state is designated the start state.
zero or more states are designated final states.
each edge is directed from one state to another.
each edge may be labeled:
Typically with an event/reaction pair.
Sometimes in other ways.

Example: Asynchronous System


The start state is named Off

There are no final states
Only events appear (not reactions)
The delta event represents the passage of some
amount of time
The above is an asynchronous system
Events may happen at variable intervals.

A serial adder
Formalizing Finite State Automata
Directed Graphs
Defn: A directed graph, D = (V, E, ), consists of
A set of vertices V
A set of edges E
A function : E (V V )
Example: V = {0, 1, 2} E = {a, b, c} and (a) = (0, 1),
(b) = (1, 2), (c) = (2, 0)

Defn: A walk in a directed graph, D = (V, E, ), is an alternating sequence of vertices and

edges (v0, e1, v1, e2, ..., en, vn) where (ei) = (vi1, vi), for i {1, 2, ..., n}.

Finite State Automata

Defn: A finite state automaton (FSA), A = (V, E, , s, F, , , ) consists of
(V, E, ) is a finite directed graph
s V is a start state
F V is a set of final states
is a set of input symbols (events)
is a set of output symbols (reactions)
: E ( ) is a labelling function
Each walk (v0, e1, v1, e2, ..., en, vn) in the graph D = (V, E, ) where v0 = s gives rise to a
behaviour in the automaton (1/1, 2/2, ..., n/n) where (ei) = (i, i), for each i {1,
2, ..., n}.
DFA Minimization
DFA is (Q,_, , I, F)
Q Finite set of states.
is the finite alphabet.
q0 Q the initial states.
F Q set of final states.
: Q _ Q, transition function (total).
Notation: We use q q to denote (q, a) = q.
A run of DFA A on u = a0, a1, . . . , an1 is a sequence of states q0, q1, . . . , qn s.t.
qi ai qi+1 for 0 i < n.
For a given word w the DFA has a unique run.
A run accepting if last state qn F.
Language accepted by AL(A) = {u _ | A has an accepting run on u}.A langauge
accepted by a DFA is called a regular language.

Construct finite automata which accepts the languages defined by the following regular

(ii) b((aab a4)b)a

Regular Expression
Regular expressions define formal languages as sets of strings over a finite alphabet. Let
denote a selected alphabet. Then is a regular expression that denotes the empty set and is a
regular expression that denotes the set containing the empty string as its only element.
, then is a regular expression that denotes the set whose only element is string . If
and are regular expressions denoting sets
, then

is a regular expression denoting the set

, where

denotes the union.

is a regular expression denoting the set of all concatenations of
is a regular expression denoting closure of
concatenations of strings from

and ,

, that is, the set of zero or more

The sets defined by regular expressions are called regular sets, and a set is regular iff it is
defined by a right linear grammar.
A regular expression is ambiguous when there exists a string which can be constructed in two
different ways from the regular expression.
Eg:a((ab)cd a(ababcb)a is Ambiguous. For instance, the string a can be
constructed by using a*((ab)cd or a(ababcb)a.
Q.Construct regular expressions representing languages, over the alphabet {a, b, c}, in which
for every string w it holds that:
The number of as in w is even.

There are 4i+ 1 bs in w. (i 0)
(a c)b(a c) )*((b(aUc))4)*
|w| = 3i. (i 0)
Q. Consider the regular expression(a(cd)b)*
Find a string over {a, b, c, d}4 which matches the expression.
abab matches.
Q. Find a regular expression for the language L over = {a, b} consisting of strings which
exactly two or exactly three bs.
1. aba is the set of strings with exactly one b.
2. ababa is the set of strings with exactly two bs.
3. abababa is the set of strings with exactly three bs.
4. The language L is then ababa abababa.
Minimum spanning trees
A tree is an undirected graph T = (V, E) satisfying all of the following conditions:
(a) T is connected,
(b) T is acyclic,
(c) |E| = |V | 1.
However, any two conditions imply the third.
A spanning tree of an undirected graph G = (V, E) is a subgraph which is a tree and which
connects all the vertices. (If G is not connected, G has no spanning trees.)
A minimum spanning tree is a spanning tree whose total sum of edge costs is minimum.
Compute a minimum spanning tree of the following graph:

Prim's algorithm.
X is a tree, and we repeatedly set S to be the edges between the vertices
of X and the vertices not in X, adding edges until X spans the graph. Thus we are always
adding the closest" vertex to the tree. The implementation of this is almost identical to that of
Dijkstra's algorithm.
Let G = (V,E) be a weighted, connected graph. Let T be the edge set that is grown in Prim's
algorithm. The proof is by mathematical induction on the number of edges in T and using the
MST Lemma.
Basis: The empty set is promising since a connected, weighted graph always has at least
one MST.
Induction Step: Assume that T is promising just before the algorithm adds a new edge e =
(u,v). Let U be the set of nodes grown in Prim's algorithm. Then all three conditions in the
MST Lemma are satisfied and therefore T U e is also promising.
When the algorithm stops, U includes all vertices of the graph and hence T is a
spanning tree. Since T is also promising, it will be a MST.
Grow a Tree
Start by picking any vertex to be the root of the
While the tree does not contain all vertices in the graph find shortest edge leaving the tree
and add it to the tree .
Step 0: Choose any element r; set S={r} and A=. (Take r as the root of our spanning tree.)
Step 1: Find a lightest edge such that one endpoint is in S and the other is in V\S. Add this
edge to A and its (other) endpoint to S.
Step 2: If V\S= , then stop & output (minimum) spanning tree(S,A). Otherwise go to Step 1.
The idea: expand the current tree by adding the lightest (shortest) edge leaving it and its
Implementation of Prim's Algorithm
Use two arrays, closest and lowcost.
For i V - U, closest[i] gives the vertex in U that is closest to i
For i V - U, lowcost[i] gives the cost of the edge (i, closest(i))
Illustration of Prim's algorithm

Step 1:

U = {1} V-U={2,4,5,6}



Select vertex 3 to include in U

Step 2:
U = {1, 3}

V - U = {2, 4, 5, 6}




Now select vertex 6

Step 3:
U = {1, 3, 6}

V - U = {2, 4, 5, 6}




Now select vertex 4, and so on

Kruskal's Algorithm
This minimum spanning tree algorithm was first described by Kruskal in 1956 in the
same paper where he rediscovered Jarnik's algorithm. This algorithm was also
rediscovered in 1957 by Loberman and Weinberger, but somehow avoided being renamed
after them. The basic idea of the Kruskal's algorithms is as follows: scan all edges in
increasing weight order; if an edge is safe, keep it (i.e. add it to the set A).
algorithm Sort the edges. Repeatedly add the lightest edge that doesn't create a
cycle, until a spanning tree is found.
Notice that in Prim's we explicitly set S based on X, whereas here we implicitly choose" the
cut S after we find the lightest edge that doesn't create a cycle. In other words, we don't
actually find a cut corresponding to the edge e to be added, but we know that one must exist
if not, adding e would create a cycle.

Overall Strategy
Kruskal's Algorithm, as described in CLRS, is directly based on the generic MST
algorithm. It builds the MST in forest. Initially, each vertex is in its own tree in forest. Then,
algorithm consider each edge in turn, order by increasing weight. If an edge (u, v) connects
two different trees, then (u, v) is added to the set of edges of the MST, and two trees
connected by an edge (u, v) are merged into a single tree on the other hand, if an edge (u, v)
connects two vertices in the same tree, then edge (u, v) is discarded.
A little more formally, given a connected, undirected, weighted graph with a
function w : E R.

Starts with each vertex being its own component.

Repeatedly merges two components into one by choosing the light edge that connects
them (i.e., the light edge crossing the cut between them).

Scans the set of edges in monotonically increasing order by weight.

Uses a disjoint-set data structure to determine whether an edge connects vertices in

different components.

Operation of Kurskal's Algorithm.

Step 1. In the graph, the Edge(g, h) is shortest. Either vertex g or vertex h could be
representative. Lets choose vertex g arbitrarily.

Step 2. The edge (c, i) creates the second tree. Choose vertex c as representative for
second tree.

Step 3. Edge (g, g) is the next shortest edge. Add this edge and choose vertex g as

Step 4. Edge (a, b) creates a third tree.

Step 5. Add edge (c, f) and merge two trees. Vertex c is chosen as the representative.

Step 6. Edge (g, i) is the next next cheapest, but if we add this edge a cycle would be
created. Vertex c is the representative of both.

Step 7. Instead, add edge (c, d).

Step 8. If we add edge (h, i), edge(h, i) would make a cycle.

Step 9. Instead of adding edge (h, i) add edge (a, h).

Step 10. Again, if we add edge (b, c), it would create a cycle. Add edge (d, e) instead to
complete the spanning tree. In this spanning tree all trees joined and vertex c is a sole