Notes All5units
Notes All5units
Arshi Husain,
Asst. Professor
USICT, GGSIPU
TOC / TAFL Playlist:
https://shorturl.at/xzuIM
[email protected]
https://shorturl.at/4sLZo
Theory Of Computation
What is Automata Theory?
Automata theory is the study of abstract machines and automata,& the computational problems that can be
solved using them. It is the combinational study of theoretical computer science and discrete mathematics.
TOC is a branch of computer science that explores the fundamental capabilities and limitations of
computers. It describes the various abstract models of computation, represented mathematically & focuses
on understanding what problems can be solved by a computer, how efficiently they can be solved, and how to
on resources needed.
Basic Terminology
Automata: It is a self-operating machine or abstract computational systems that
follows predefined rules to process inputs and produce outputs. Eg, Elevator,
Automatic doors etc
Symbol: Basic building blocks. Example: a,b,c,… , 0,1,2,3,….9 and special characters.
Empty String : Symbol ‘ε’ (epsilon) is used to denote empty string and that is the
string consisting of zero symbol. It is also called as null string
Basic Terminology
Length of String : The length of a string is number of symbols in the string. It
denoted by |w|.
Example 1: If ∑={0,1} & w=01010 Then, |w|=5 Example2: If w =ε then |w|=0
Prefix: It is any number of leading symbol of string. Example-: let w=abc Prefix of
w are ε,a,ab,abc.
Suffix: Any number of trailing symbols of string. If w=abc, suffix are ε,c,bc,abc
Concatenation of String-: if w and x are two string then the concatenation of two
string is denoted by wx. Example-: w=1110 and x=0101 Then xy=11100101
Basic Terminology
Language-: It is the set of string over the alphabet ∑ which follows a set of
rules called the grammar L Or otherwise we can say set of string generated by
grammar taking symbol from ∑ .
Grammar-: A set of rules used to generate the string for a particular language.
Power of an alphabet
If Σ is an alphabet, the set of all strings can be expressed as a certain length from
that alphabet by using exponential notation. The power of an alphabet is denoted by
and is the set of strings of length k.
Example: If ∑={0,1}
It representations:
❏ In switching theory and design and analysis of digital circuits automata theory
is applied.
❏ Design and analysis of complex software and hardware systems.
❏ It plays an important role in complier design
❏ To prove the correctness of the program automata theory is used.
❏ It is base for the formal languages and these formal languages are useful of
the programming languages.
Finite Automata Model
❏ After reading each symbol, control moves from one state to another along
the transition that has that symbol as its label.
❏ When M reads the last symbol of w, then the string ‘w’ is said to be
accepted by the finite automata, if there exist a transition for which it
starts at the initial state and ends in any one of the final states,. δ* (q0, w)
= qf for some qf ∈ F.
L(M) =
Types of Finite Automata
Deterministic Finite Automata (DFA)
Deterministic Finite Automaton is a FA in which there is exactly one path for a
specific input from current state to next state. i.e., there is a unique
Two parameters are passed to this transition function: (i) current state and
(ii) input symbol. The transition function returns a state which can be called as next
state.
δ ( current_state, current_input_symbol ) = next_state
Example 1: δ ( q0, a ) = q1, means on a state q0 take an input symbol a machine will
make a transition q1
b
Q12 Design a minimal DFA that accepts all strings
over the alphabet ∑ = {a, b} such that every accepted
string w, starts and ends with the different symbol
Q13 Design a minimal DFA that accepts all strings
over the alphabet ∑ = {a, b} such that every accepted
string w, starts with the substring s=’abb’
Q14 Design a minimal DFA that accepts all strings
over the alphabet ∑ = {a, b} such that every accepted
string w, ends with the substring s=’bab’
Q14 Design a minimal DFA that accepts all strings
over the alphabet ∑ = {a, b} such that every accepted
string w, ends with the substring s=’bab’
Q15 Design a minimal DFA that accepts all strings
over the alphabet ∑ = {a, b} such that every accepted
string w, contains the substring s=’aba’
Q16 Design a minimal DFA that accepts all strings
over the alphabet ∑ = {a, b} such that every accepted
string w, is like w=AX. A=aaa/bbb?
Q17. Design a minimal DFA that accepts all strings
over the alphabet ∑ = {a, b} such that every accepted
string w, is like w=XS. S=aaa/bbb?
Q18. Design a minimal DFA that accepts all strings
over the alphabet ∑ = {a, b} such that every accepted
string w, is like w=XSX. S=aaa/bbb?
Q19 Design a minimal DFA that accepts all strings
over the alphabet ∑ = {a, b} such that every accepted
string ‘w’ should be:
a. |w|=4
b. |w|<=4
c. |w|>=4
Q20 Design a minimal DFA that accepts all strings
over the alphabet ∑ = {a, b} such that every accepted
string ‘w’ must consist of exactly two a’s.,i.e.|w|a=2
Q21 Design a minimal DFA that accepts all strings
over the alphabet ∑ = {a, b} such that every accepted
string ‘w’ must consist of at least two a’s.,i.e.|w|a>=2
Q22 Design a minimal DFA that accepts all strings
over the alphabet ∑ = {a, b} such that every accepted
string ‘w’ must consist of at most two a’s.,i.e.|w|a<=2
Q23 Design a minimal DFA that accepts all strings
over the alphabet ∑ = {a, b} such that such that
every accepted string ‘w’ should be like |w|=0 (mod 3)
Q24 Design a minimal DFA that accepts all strings
over the alphabet ∑ = {a, b} such that such that
every accepted string ‘w’ should be like |w|=1 (mod 4)
Q25 Design a minimal DFA that accepts all strings
over the alphabet ∑ = {a, b} such that every accepted
string ‘w’, must contain 0(mod 2) number of a’s, i.e.
|w|a = 0(mod 2)
Q26 Design a minimal DFA that accepts all strings
over the alphabet ∑ = {a, b} such that every accepted
string ‘w’, must contain 2(mod 3) number of a’s, i.e.
|w|a = 2(mod 3)
Q27 Design a minimal DFA to check whether given
unary number is divisible by three.
Q28 Design a minimal DFA to check whether given
binary number is divisible by 2.
Q29 Design a minimal DFA to check whether given
binary number is divisible by 3.
Q30 Design a minimal DFA to check whether given
binary number is divisible by 4.
NFA (Non-Deterministic finite automata)
δ: Q x ∑ →2Q
POINTS TO REMEMBER
€-closure(Φ) = Φ
EQUIVALENCE BETWEEN NULL NFA TO NFA
The only exception to this rule is when the start symbol S produces the empty string
directly:This special case is allowed to ensure that the grammar can generate the
empty string as part of the language. However, this exception applies strictly to the
start symbol and not to other non-terminals.
Type 2: Context-Free Grammar
Languages recognized by Pushdown Automata are known as Type 2 Grammar.
Context-free grammar represents context-free languages.
For grammar to be context-free, it must be context-sensitive. Grammar Production
for Type 2 is given by
A→γ, where A is a single non-terminal and γ is a string of terminals and
non-terminals. The left-hand side of the rule is always a single non-terminal.
Dead State- It is basically created to make the system complete, can be defined
as a state from which there is no transition possible to the final state
Unreachable State- It is that state which cannot be reached starting from initial
state by parsing any input string
Equivalent states- Two states q1 and q2 are equivalent (denoted by q1≅ q2) if
both δ (q1, x) and δ (q2, x) are final states or both of them are non-final states for
all x ∈ ∑*. If q1 and q2 are k-equivalent for all k ≥ 0, then they are k-equivalent.
These states behave in same manner on each and every input string. That is for
any string w where w Î S* either both of the states will go to final state or both will
go to non-final state
Regular Expression
● The language accepted by finite automata can be easily described by simple expressions
called Regular Expressions. It is the most effective way to represent any language.
● The languages accepted by some regular expression are referred to as Regular languages.
● A regular expression can also be described as a sequence of pattern that defines a string.
● Regular expressions are used to match character combinations in strings.
● Two regular expressions P and Q are equivalent (we write P = Q),if P and Q represent the same
set of strings.
For instance:
In a regular expression, x* means zero or more occurrence of x. It can generate {e, x, xx, xxx, xxxx,
.....}
In a regular expression, x+ means one or more occurrence of x. It can generate {x, xx, xxx, xxxx, .....}
Regular Language
Moore machine also places its output in the Mealy Machine places its output on the
state. transition.
Decidable Decidable problem is one for which there exists an algorithm that can
determine the answer (yes or no) for every input in a finite amount of time. In the
context of regular languages, decidability means that there exists a finite
procedure (algorithm) to determine certain properties of these languages.
Algorithm:
Example:
The language L={ a^n b^n | n ≥ 0 } is non-regular because a finite automaton cannot
remember how many aa's have been seen to match them with bb's.
3⃣ Show how pumping & splitting the string does NOT satisfy the pumping lemma.
"Pumping" refers to the idea that a certain
segment of a string within a language can be
repeated ("pumped") multiple times without
causing the string to fall out of the language.
=
Arden's Theorem
If P & Q are two regular expressions over Σ & if P does not contain ε, then the following equation in R given by
R = Q + RP
R = QP*
Conditions
Why?
Arden's Theorem
S→aSb/ε
Consider the following grammar & and identify its language (CFG TO CFL)
Ques. Consider the following grammar & and identify its language (CFG TO CFL)
Ques. Consider the following grammar & and identify its language (CFG TO CFL)
L={a^nb^m |n≥0,m>0}
Consider the following grammar & and identify its language (CFG TO CFL)
Convert CFL to CFG
1. S → aSb
S → ab
1. S → aSb | bb
Convert CFL to CFG
3. S→aaSb
S→/ϵ
4. S→aaSb
S→aaa
Convert CFL to CFG
Convert CFL to CFG
Convert CFL to CFG
Write CFG that generates a language which accepts all
palindromic strings of even length over the alphabet {a,b}
Write CFG that generates a language which accepts all
palindromic strings of odd length over the alphabet {a,b}
Write CFG that generates a language which accepts all
palindromic strings over the alphabet {a,b}
REGULAR GRAMMARS
Regular grammar generates regular language.
Right and Left linear Regular Grammars
Conversion of RLG to LLG for language L
Step 1: Reverse the FA for language L
Step 2: Write the RLG for it.
Step 3: Reverse the right linear grammar
(RHS).
Ex: FA for accepting strings that
start with b
FA TO CFG CONVERSION
EXAMPLES
EXAMPLES
PDA to CFG Conversion
CFG to PDA Conversion
Conversion of RLG to LLG for language L
Step 1: Reverse the FA for language L
Step 2: Write the RLG for it.
Step 3: Reverse the right linear grammar.
Example: FA for accepting strings that
start with b
Simplification of CFG
The process of Removal of Unit productions, Null productions and Useless
Symbols is known as Simplification of CFG.
S→AbB/bB/Ab/b
S →a
S →b
S→aSb/ε S' → S / ε
S→ a S b/ ab
S' → S / ε
S→BA/A/AB/B/AA
A→0A/0
B→1B/1
S' → S / ε
S→AB
S→AB/B/A
A→a/ε
A→a
B→b/ε
B→b
S → 0X | 1Y | 01
X → 0S | 00
Y → 0S | 00 | 1
Step 3: Repeat the first and the second steps until all the unit productions are removed.
Remove Unit Productions from:
S → 0X | 1Y | Z
X → 0S | 00
Y → 1 | X
Z → 01
So,the grammar
becomes:
S → 0X | 1Y | 01
X → 0S | 00
Y → 0S | 00 | 1
Remove Unit Productions from:
S → aA b
A → B / a
B → C / b
C → D / c
D → d
So,the grammar
becomes:
S → a A b
A → a | d | c | b
Remove Useless Productions from:
S → aAB | bA | aC Grammar after
A → aB | b
B → aC | d removing useless C
S → aAB | bA
A → aB | b
B → d
Step 1.2: Check Reachability
Step 2. Eliminate terminals from RHS if they exist with other terminals or
non-terminals. e.g,; production rule X->xY can be decomposed as:
X->ZY
Z->x
Since CNF does not allow mixed terminals and non-terminals, we introduce new variables
A→a
B→b
The rule S → ASB is not in CNF because the right-hand side has three symbols.
S → AC
C → SB
EXAMPLES
1. 2.
Greibach Normal Form (GNF)
S → AY
X → x | SX
Y→y
A→x
EXAMPLES
Pushdown Automata
A Pushdown Automata (PDA) is a way to implement context-free
Grammar
1. It is more powerful than FSM.
2. FSM has very limited memory but PDA has more memory.
3. PDA= Finite State Machine + Stack
Block diagram of pushdown automata
1. An input tape
2. A finite Control Unit.
3. A stack with infinite size.
Formal Definition
A Pushdown Automata (PDA) can be defined as as a 7-tuple (Q, ∑, Γ, δ, q0, I, F):
● Q is the set of states
● ∑is the set of input symbols
● Γ is the set of pushdown symbols (which can be pushed and popped from stack)
● q0 is the initial state
● Z is the initial pushdown symbol (which is initially present in stack)
● F is the set of final states
● δ is a transition function which maps Q x {Σ ∪ ∈} x Γ into Q x Γ*. In a given state, PDA
will read input symbol and stack symbol (top of the stack) and move to a new state
and change the symbol of stack.
Push,Pop and NOOP/Skip Operations on PDA
Construct a PDA for the language { 0^n 1^n | n >=1 }
To construct a PDA accepting by empty stack for the language L = {0^n1^n |
n>=1}, we can follow these steps:
1. Push a special symbol Z0 (not in the input alphabet) to the stack to mark the
bottom of the stack.
2. Read the input symbol 0 and push it to the stack.
3. Repeat step 2 until all 0s are read.
4. Read the input symbol 1 and pop the topmost symbol (which should be 0).
5. Repeat step 4 until all 1s are read.
6. Check if the stack is empty/contains only Z0 at this point. If yes, accept the
input.
Construct a PDA for the language { 0^n 1^n | n >=1 }
Transition Diagram
Construct a PDA for the language { 0^n 1^n | n >=1 }
Check the IP string: Transition
w = 0011 Diagram
Check the
IP string:
w=aabb
Construct a PDA for the language { a^n b^2n | n >=1 }
Construct a PDA for the language { a^n b^2n | n >=1 }
Construct a PDA for the language {a^n b^n U a^n b^2n | n >=1 }
Construct a PDA for the language {a^n b^n U a^n b^2n | n >=1 }
Two stack PDA for L= aⁿbⁿcⁿ |n>=1
Push 'a' into Stack 1: For every 'a' in the input, push it onto the first stack.
Pop 'a' and Push 'b' into Stack 2: When 'b' appears, pop 'a' from Stack 1 and push 'b' onto Stack 2.
Pop 'b' for each 'c': When 'c' appears, pop 'b' from Stack 2.
Accept if Both Stacks are Empty: If the input is fully read and both stacks are empty, the string is
accepted.
Two stack PDA
L=aⁿbⁿcⁿdⁿ |n>=1
Push 'a' into Stack 1: For each 'a' in the input, push it onto Stack 1.
Pop 'a' and Push 'b' into Stack 2: When 'b' appears, pop 'a' from Stack
1 and push 'b' onto Stack 2.
Pop 'b' and Push 'c' into Stack 1: When 'c' appears, pop 'b' from Stack
2 and push 'c' onto Stack 1.
Pop 'c' for each 'd': When 'd' appears, pop 'c' from Stack 1.
Accept if Both Stacks are Empty: If the input is fully read and both
stacks are empty, the string is accepted.
PDA for wcw^R w ε (a,b)+
STACK Transition Function
// Decision step
δ(q0, c, a) = (q1, a)
δ(q0, c, b) = (q1, b)
δ(q1, b, b) = (q1, ε)
δ(q1, a, a) = (q1, ε)
δ(q1, ε, Z) = (qf, Z)
Example : Process the input string: "abbcbba" for the above DPDA
Eg: w=ab
DPDA Vs NPDA
Pumping Lemma for CFLs
1. Purpose: Used to prove that a language is not context-free by showing
that no matter how a string is divided, it cannot be pumped while staying in
the language.
2. Existence of a Constant p: There exists a pumping length p (depends on
the language) such that any string w with ∣w∣≥p can be split as: w =
uvwxy
3. Contradiction Approach: To prove L is not context-free:
● Assume L is context-free.
● Pick a string w with ∣w∣≥p
● Show that for every possible split, at least one pumped version
● This contradiction proves L is not context-free.
Pumping Lemma for CFLs
Example1
Example2
Example2
Let z = aabbbb
Closure properties of Context-Free Language
Context-Free languages are closed under:
a. Union
b. Concatenation
c. Kleene Closure
Not closed under:
a. Intersection
b. Complementation
Union
Union Example 2:
Concatenation
Concatenation Example 2
Kleene Closure
L1 = L* is also a CFL
Intersection
Complement
Which is invalid,
therefore , not closed
under complement
LL(k) Grammar
If k=1, then we have, LL(1) Grammar
● 1st L indicates → Reading input string from left to right.
● 2nd L indicates → Leftmost derivation
● 1 indicates →Looking ahead terminal symbol in the input string.
● Used for Top Down Parsing Explicit Parse Tree
Example: Consider the Grammar:
Implicit Parse Tree
PDA
TM
TMs are able to do any of the following Operations on Tape
1) Read a symbol from the tape.
2) Write a symbol to the tape.
3) Move the tape head, one step LEFT.
4) Move the tape head, one step RIGHT.
Components of Turing Machine
TAPE:
A 2-way infinite tape, divided into cells.Each cell is capable of holding only one tape symbol.
Purpose: Acts as the machine’s memory, allowing it to read from and write to the tape.
TAPE HEAD:
A read/write head that moves along the tape. It can read the symbol in the current cell, write a new
symbol, and move left or right.
Purpose: Facilitates interaction with the tape by reading symbols and updating them.
to be written in the tape, and the direction which the head will moves. δ:Q×Γ→Q×Γ×
The transition δ(q0, a) = (q1, X, R), means that at q0 state if ‘a’ occurs
{L,R} then replace it with ‘X’ ,change the state to q1 and move to right.
● q0: The start state, a member of Q, where the finite control is found initially.
● B: the blank symbol. This symbol is in Γ but not in Σ.
● F: the set of final or accepting states, a subset of Q.
Modifications of Turing Machine
1. Multi-tape Turing Machine
2. Turing Machine with stay option d: Q ×ℾ -> Q× ℾ × (L/R/S)
3. Multi-dimensional Turing Machine d: Q ×ℾ -> Q× ℾ × (L/R/U/D)
4. Turing Machine with one way infinite tape (Semi infinite tape)
5. Multi Read/Write head points
6. Multi-head Turing Machine
7. Offline TM: have a restriction that input can’t be changed (2 tapes)
8. Jumping TM: where the tape head can jump to non-adjacent positions on the tape
9. Non erasing TM: where input can not be converted to blank
10. Always writing TM
11. UTM
12. Non-Deterministic Turing Machine
13. TM without Writing Capacity (FA)
14. TM with Tape used as Stack
15. TM with finite tape
16. TM with Input Size Tape (LBA)
Church’s Thesis
Church’s Thesis
According to the Church-Turing thesis:
-Anything that can be done on any existing digital computer can also be done by a Turing
machine/ Everything that can be computed, can be computed by a Turing machine / What
could naturally be called as an effective procedure, can be realized by a turing machine.
- This thesis cannot be proven but is believed on the basis of the amount of evidence that
supports it. No one has yet been able to suggest a problem, solvable by what we intuitively
consider an algorithm, for which a Turing machine program cannot be written.
- Computer scientists have devised several alternative models of computation, but none of
them is more powerful than the Turing machine model.
Let M be the Turing Machine for above AIM, hence it can be define as M(Q, Σ, Г, δ, q0, B, F) where
Q: set of states: {q0, q1, q2}
Σ: set of input symbols: {0, 1}
Г: Set of Tape symbols: {0, 1, B}
q0: initial state (q0)
B: Blank Symbol (B)
F: set of Final states: { } [Note: Here, set of final states is null as here we have to design turing
machine as enumerator.]
δ: Transition Function:
Turing machine for 2’s Complement
1. Move the input head at right direction, till it reaches to B. If B encounter then
change state from q0 to q1.
2. Now, start reading input symbol right to left one by one.
3. If the input symbol is 0, move the input head left and do the same for all 0 till 1
encounter.
4. If the input symbol is 1, move the input head left and change its state from q1 to
q2.
5. Now, if the input symbol is 0, make it 1 and if input symbol is 1 make it 0 till
reach to the starting point.
Transition Table
Transition Diagram
Turing machine for L = {w c w | w ∊ {0, 1}* }?
Turing machine for addition of two number in unary
Turing machine for converting unary number into binary number
Universal Turing Machine (UTM)
Motivation: We need a single m/c which can solve all type of problems
❖ A Universal Turing Machine is a reprogrammable Turing machine capable of simulating the
behavior of any other Turing machine, effectively serving as a programmable computer that can
execute any computable function.
❖ A standard Turing machine can simulate only a single computation problem, so if we want to
solve another computation problem, then another Turing machine is required to be constructed,
but in case of a UTM, the same UTM can be used to solve any computation problem.
❖ Power of a UTM is the same as the power of a standard TM as both solve the same set of
computational problems. (also a digital computer)
❖ Turing complete means a system can perform any computation that a Turing machine can,
given enough time and memory.
Universal Turing Machine (UTM)
Input to UTM is description of TM () and string w.
It consists of 3 tapes:
1. 1st tape stores the binary encoding of TM.
2. 2nd tape stores string w.
3. 3rd tape stores the state of TM.
Action: Accept, Reject, Loop
Linear Bounded Automaton (LBA)
An LBA is a restricted type of Turing Machine where the tape is bounded by the length of the input.
LBAs are precisely the machines that recognize context-sensitive languages.
LBA is more powerful than PDA but less powerful than unrestricted Turing Machines.
A linear bounded automaton can be defined as an 8-tuple (Q, X, ∑, q0, ML, MR,
δ, F) where −
Halting means:
● Let an integer function be f (x,y) = x+y. We have to solve this function using Turing
Machine. so , input tape must represent the input arguments.
● Let the number of '0' be used to represent the argument. But there must be a separator
to differentiate the number of '0' for each argument. In Turing machine, blank space is
used to separate the arguments on the tape.
Undecidability
Undecidability Problems
Undecidable problems are decision problems where no algorithm can be constructed to always provide a correct "yes" or "no"
Eg. Fermat's Last theorem is undecidable, which states that no three positive integers x, y, and z can satisfy the following equation
for any integer value of n >2.
xⁿ + yⁿ = zⁿ
Question:
Given a program and an input, will the program eventually halt (stop running) or run forever?
Why it's undecidable:
It's impossible to create an algorithm that can always correctly determine if any arbitrary program will halt. Alan Turing proved this
in 1936, demonstrating the existence of undecidable problems.
Question:
Given a list of pairs of strings (dominoes), can you arrange them in a way such that concatenating the top strings equals the
concatenation of the bottom strings?
Why it's undecidable:
There's no algorithm that can always determine if such an arrangement exists.
Post Correspondence Problem (PCP)
Def 2: we have N number of Dominos (tiles). The aim is to arrange tiles in such
order that string made by Numerators is same as string made by Denominators.
Post Correspondence Problem
Q. Find whether the lists M = (ab, bab, bbaaa) and N = (a, ba, bab) have a post
correspondence solution? For x2 x1 x3 ∆ y2 y1 y3
2113
PCP Examples
Check does PCP with two lists X= (0101, 000111, 001, 10, 01,
00) and Y= (0101000, 11, 1001,
100, 10, 0) have a solution?
Reducibility
Reducibility means to transfer knowledge about one problem to another
Formal definition: If there exists a computable function f such that: x ∈ P₁ ⇔ f(x) ∈
P₂
a) P₁ is decidable
P₃ is undecidable, then,
P₂ is ________ ?
So, to prove that PCP is undecidable, we want to reduce the TM halting problem to
PCP.
So we take:
Given:
● TM States: q0, q1, q2 (final)
● Input: w = aba
● Alphabet:
○ Tape symbols: Γ = {a, b, x, B} (includes blank B and symbol x used for marking)
Undecidability of the Post Correspondence Problem
We have a Domino [#/#] , and the given TM Transitions are :
Now we need to follow the following steps to convert the given Turing m/c into a format that can be simulated
using Post Correspondence Problem (PCP).
Step 1:
Step 4:
q2
Undecidability of the Post Correspondence Problem
Step 6:
Undecidability of the Post Correspondence Problem
Example: Subtraction of two positive numbers m and n, f(m, n) = m-n; if m>=n, otherwise it's not defined.
Primitive Recursive Functions: These are a subset of recursive functions that are defined using only basic
initial functions (such as zero, successor, and projection functions) and can be formed through a finite
combination of composition and recursion. They are always total functions, meaning they produce a result for
every possible input. (We can create recursive func using the basic initial func)
Complexity Theory
Complexity Theory
Solvable - A problem is said to be solvable if either we can solve it or if we can prove that the
problem cannot be solved
Unsolvable - A problem is said to be unsolvable if neither we can solve it, nor we can proof
that the problem can not be solved
Decidable- Decidable problem is one for which there exists an algorithm that can determine
the answer (yes or no) for every input in a finite amount of time. In terms of formal languages,
a language is decidable if there exists a halting Turing machine that always decides
membership in the language. Such a language is also called a recursive language
Undecidable-Undecidable problems are those for which no algorithm can determine the
correct answer (yes or no) for all possible inputs. In other words, there is no Turing machine
that always halts with a correct decision for every input. In terms of formal languages, a
language is undecidable if there does not exist a halting Turing machine that decides
membership in the language. Such languages are called non-recursive languages.
Complexity Classes
Polynomial Time Algorithms
Examples of P Problems:
■ Insertion sort
■ Merge sort
■ Linear search
■ Matrix multiplication
■ Finding minimum and maximum elements from the array
NP-Class Problems
■ NP (Non-deterministic polynomial time) problems are a set of problems that can not be solved in
polynomial time, but given the solution, it can be verified in polynomial time.
■ NP includes all problems of P, i.e. P ⊆ NP.
Measuring Space: A Turing Machine M runs in space S(n) if, for all inputs of length n, M
uses at most S(n) cells in total on its work tapes.
Space Complexity of a Turing machine = The maximum number of tape cells it scans
or uses during computation on any input of size n.
Formal Definition: Let M be a Turing machine, and let f(n) be a function, We say that
M runs in space f(n) if : For every input of length n, the Turing machine never scans
more than f(n) tape cells on any computation branch (for non-deterministic machines,
on any branch)
Space Complexity
The Turing machine never scans more than f(n) tape cells on any computation
branch (for non-deterministic machines, on any branch), i.e
● It never uses more than f(n) space (tape cells) along that path.
So even if there are many possible branches, each one individually must obey the
space limit f(n).
Space Complexity Classes
1. DSPACE(f(n))
2. NSPACE(f(n))
Problem
Solvable Unsolvable
Decidable Undecidable
P-Type NP-Type
Ackermann Function
The Ackermann function is a two-parameter function that takes non-negative integers as
inputs and produces a non-negative integer as its result.The Ackermann function is total. The
function is defined as follows:
UNIT 4: NPDA
DPDA
Pumping Lemma for CFL
Closure Properties of CFL
Decision Problems of CFL