1 of 58

Modeling Computation

13.1 Languages and Grammars

FREE: For Complete Playlist: https://www.youtube.com/c/FahadHussaintutorial/playlists

For Code, Slide and Books: https://fahadhussaincs.blogspot.com/

Chapter 13

Theory of computation

Compiler design

Automata theory

2 of 58

Chapter 13 Modeling Computation

13.1 Languages and Grammars

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 the 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”.

Now, let’s understand the basic terminologies, which are important and frequently used in the Theory of Computation. 

3 of 58

4 of 58

5 of 58

6 of 58

7 of 58

8 of 58

Symbol:

A symbol (often also called a character) is the smallest building block, which can be any alphabet, letter, or picture.

Alphabets (Σ):

Alphabets are a set of symbols, which are always finite.

String:

A string is a finite sequence of symbols from some alphabet. A string is generally denoted as w and the length of a string is denoted as |w|.

Empty string is the string with zero occurrence of symbols,

represented as ε. Nmber of Strings (of length 2) that can

be generated over the alphabet {a, b}:

- -

a a

a b

b a

b b

Length of String |w| = 2

Number of Strings = 4

9 of 58

10 of 58

11 of 58

12 of 58

13 of 58

14 of 58

15 of 58

16 of 58

13.2 Finite-State Machines with Output

17 of 58

  • Finite state machine is used to recognize patterns.
  • Finite automata machine takes the string of symbol as input and changes its state accordingly. In the input, when a desired symbol is found then the transition occurs.
  • While transition, the automata can either move to the next state or stay in the same state.
  • FA has two states: accept state or reject state. When the input string is successfully processed and the automata reached its final state then it will accept.

Finite state machine

18 of 58

NDFA

NDFA refer to the Non Deterministic Finite Automata. It is used to transit the any number of states for a particular input. NDFA accepts the NULL move that means it can change state without reading the symbols.

NDFA also has five states same as DFA. But NDFA has different transition function.

Transition function of NDFA can be defined as:

δ: Q x ∑ →2Q

Example

See an example of non deterministic finite automata:

  1. Q = {q0, q1, q2}  
  2. ∑ = {01}  
  3. q0 = {q0}  
  4. F = {q3}  

19 of 58

DFA

DFA stands for Deterministic Finite Automata. Deterministic refers to the uniqueness of the computation. In DFA, the input character goes to one state only. DFA doesn't accept the null move that means the DFA cannot change state without any input character.

DFA has five tuples {Q, ∑, q0, F, δ}

Q: set of all states

∑: finite set of input symbol where δ: Q x ∑ →Q

q0: initial state

F: final state

δ: Transition function

Example

See an example of deterministic finite automata:

20 of 58

21 of 58

22 of 58

23 of 58

24 of 58

25 of 58

26 of 58

27 of 58

28 of 58

29 of 58

30 of 58

31 of 58

32 of 58

33 of 58

34 of 58

35 of 58

36 of 58

Regular Expressions

37 of 58

38 of 58

39 of 58

40 of 58

41 of 58

42 of 58

43 of 58

44 of 58

45 of 58

Construct a TM for the language L = {0n1n2n} where n≥1

The simulation for 001122 can be shown as below:

46 of 58

The same TM can be represented by Transition Diagram:

The following are the different types /Varients of turing machines:

  • Multi-tape turing machine.
  • Multi-head turing machines.
  • Multi-track turing machines.
  • Semi-infinite turing machines.
  • Universal Turing Machine.
  • Alternating Turing machine.
  • Non-Deterministic Turing Machine.
  • Unambiguous Turing Machine.

47 of 58

48 of 58

49 of 58

50 of 58

51 of 58

52 of 58

53 of 58

54 of 58

55 of 58

56 of 58

57 of 58

58 of 58