1. Applications of finite automata

Finite automata

Finite automata

A finite automata is a tuple where:

  • is an alphabet (finite set of atomic symbols)
  • is a finite set of states
  • is the initial state
  • is the set of accepting states
  • is the transition function
Link to original

Examples include:

  • spell checkers
  • search engine pattern matching
  • compiler design
  • specifying network protocols
  • chip design
  • speech recognition
  • transforming text using markup languages like XML
  • software optimisation
Link to original

2. Alphabets, words, languages

Words

Alphabet

An alphabet is a finite set of symbols. Examples of alphabets include: , and .

Link to original

Word (finite automata)

A word or string (over an alphabet ) is a finite sequence of symbols from written without commas. For example, or .

Link to original

Empty word

The empty word, denoted by , is a word over any alphabet. We assume that is not a symbol of any of our alphabets.

Link to original

Length (word)

The length of a word is . For example, or .

Link to original

Concatenation

The concatenation of words and is the word followed by the word , written . We can use the syntax .

Formally, .

Link to original

Repetition

The repetition of words can be denoted by the power, . For example, , or .

Link to original

For every word , .

Prefix

If , then is a prefix of .

Link to original

Suffix

If , then is a suffix of .

Link to original

Languages

Language

A language (over an alphabet ) is a set of words over .

For example, given .

Given :

Link to original

Link to original

3. Finite automata basics

Finite automata basics

A theoretical model for programs using a constant amount of memory regardless of the input form.

Finite control device

Finite control device: in any moment, it can be in one of its states, it is hard-wired in how it changes from one state to another. There are also some special states, such as one initial state and possible more favourable states.

  • Has a reading head.
  • It reads from an input tape: divided into cells, having a leftmost cell, each cell contains one character of the input alphabet and is fed into the machine.
Link to original

Starting finite automation

  • The finite control device is put in its unique initial state.

  • The tape contains a finite word of the input alphabet, the input, as its left end. The remainder of the tape contains only blank cells.

  • The reading head is positioned on the leftmost cell of the input tape, containing the first character of the input word.

How it works

At regular time intervals, the automaton:

  • reads one character from the input tape
  • moves the reading head one cell to the right, and
  • chooses the next state of its control device

The control device is hard-wired such that the next state depends on:

  1. the previous state
  2. the character read from the tape

As the input is finite, at some moment the reading head reaches the end of the input word (the first blank cell). If at this moment the control device is in a favourable state, then the input word is accepted by the automaton. Otherwise, the input word is not accepted, rejected.

Used for

  • Each finite automaton is a kind of ‘recognition’ or ‘decision’ device over all possible words of its input alphabet.

  • Each automaton can be ‘tried’ on infinitely many input words, and gives a Y/N answer each time.

Link to original

4. State transition diagrams

State transition diagrams

State transition diagram

We can represent the hard-wired control device of a finite automaton by a directed multigraph:

  • with the vertices representing the states
  • arrow-edges being labelled by symbols of the input alphabet
  • the initial state is marked by
  • the favourable states are double-circled
  • each arrow represents a possible transition, hard-wired in the control device: an arrow from state to state labelled by symbol indicates that, when the head is reading and the control device is in state then it should move next to state
Link to original

Automaton

digraph {
	label=A₁
	rankdir=LR
	init[shape=point]
	node[shape=doublecircle]; q;
	node[shape=circle];
	init->s
	s->s [label=a]
	s->q [label=b]
	q->q [label=b]
	q->r [label=a]
	r->r [label=a]
	r->r [label=b]
}

Input 1: Computation: word is rejected

Input 2: Computation: word is accepted

Input 3: Computation: word is rejected

Input 4: Computation: word is accepted

Input 5: Computation: word is rejected

Link to original

5. Deterministic Finite Automata

Deterministic Finite Automata

Deterministic Finite Automata

In order to describe a Deterministic Finite Automation, , we describe 5 things:

  • its states
  • its input alphabet
  • its (unique) initial state
  • its favourable (or accepting) states there can be none, or more than one
  • its transition function: for every (state, input symbol) pair we have to tell what the next state should be

A word is accepted by DFA if the computation of on input ends up in some favourable state. Otherwise, is rejected by .

Link to original

What does ‘deterministic’ mean?

Taking this diagram from earlier:

digraph {
	label=A₁
	rankdir=LR
	init[shape=point]
	node[shape=doublecircle]; q;
	node[shape=circle];
	init->s
	s->s [label=a]
	s->q [label=b]
	q->q [label=b]
	q->r [label=a]
	r->r [label=a]
	r->r [label=b]
}

Deterministic means that for each state and symbol, there is a unique arrow coming out of the state labelled by the symbol.

As it is unique, there is one, but not more than one. We can say that, the pair uniquely determines the next state. This is why DFAs are called deterministic. DFAs will never “get stuck”, it never has to choose.

Transition Table

From above, we find that:

  • States:
  • Input alphabet:
  • Initial state:
  • Favourable states:

The transition table is another way of representing the transition function of :

For each cell in the table, there is a unique state to put in. As before, the pair uniquely indetifies the next state.

Link to original

6. Vending machine example

: Vending machine example

digraph {
	label=A₂
	rankdir=LR
	init[shape=point]
	node[shape=doublecircle]; 0;
	node[shape=circle];
	init->25
	
	25[label="s₂₅"]
	20[label="s₂₀"]
	15[label="s₁₅"]
	10[label="s₁₀"]
	5[label="s₅"]
	0[label="s₀"]
	
	25->20 [label="5p"]
	20->15 [label="5p"]
	15->10 [label="5p"]
	10->5 [label="5p"]
	5->0 [label="5p"]
	
	25->15 [label="10p"]
	20->10 [label="10p"]
	15->5 [label="10p"]
	10->0 [label="10p"]
	5->0 [label="10p"]
	
	25->5 [label="20p"]
	20->0 [label="20p"]
	15->0 [label="20p"]
	10->0 [label="20p"]
	5->0 [label="20p"]
}

For this diagram:

  • states:
  • input alphabet:
  • inital state:
  • favourable states:

Word: any sequence of , and coins Accepts: all the words such that the sum of the coins is

Link to original

7. Language of a DFA

Language of a DFA

Language

A language (over an alphabet ) is a set of words over .

For example, given .

Given :

Link to original

Language of a DFA

A DFA may accept certain words, while may reject others. If we collect all words accepted by a DFA , we obtain a language: the language of a DFA is: ?

Link to original

Example

Using 4. State transition diagrams > Automaton A_1 (hover for preview), we already know:

  • That and are accepted.
  • That , and were rejected.

Hence, .

Finding the language of a finite automaton

  1. Experiment with words.
  2. Come up with a language.
  3. Test the suggested language:
    • every word that is accepted by the automaton should be in the suggested language
    • every word that is rejected by the automaton must not be in the suggested language
  4. Revise the suggested language if necessary, then go to step 3.
Link to original
Transclude of 8.-some-more-examples