Last Unit Motes
Last Unit Motes
A language L is recursive (decidable) if L is the set of strings accepted by some Turing Machine
(TM) that halts on every input.
Example
When a Turing machine reaches a final state, it halts. We can also say that a Turing machine M
halts when M reaches a state q and a current symbol ‘a’ to be scanned so that δ(q, a) is undefined.
There are TMs that never halt on some inputs in any one of these ways, So we make a distinction
between the languages accepted by a TM that halts on all input strings and a TM that never halts
on some input strings.
Recursive Enumerable Language
A language L is recursively enumerable if L is the set of strings accepted by some TM.
If L is a recursive enumerable language then −
If w ∈ L then a TM halts in a final state,
If w ∉ L then a TM halts in a non-final state or loops forever.
If L is a recursive language then −
If w ∈ L then a TM halts in a final state,
If w ∉ L then TM halts in a non-final state.
Recursive Languages are also recursive enumerable
Proof − If L is a recursive then there is TM which decides a member in language then −
M accepts x if x is in language L.
M rejects on x if x is not in language L.
According to the definition, M can recognize the strings in language that are accepted on those
strings.
1. Union
2. Intersection
3. Complement
Union of RE languages
Let’s revise union of sets;
Set 1 = {a, b, c}
Set 2 = {b, c, d}
Set 1 Union Set 2 = {a, b, c, d}
Now let’s understand the same concept in Turing Machine;
Suppose a system has 2 Turing Machines, TM1, and TM2.
G = (N,Σ,P,S)
N - It is a set of non-terminal symbols,
Σ - It is a set of terminal symbols,
P - It is a set of production rules,
S - It is a start symbol of the production.
αAβ → αγβ
where,
A ∈ N,
α,β ∈ (N∪Σ)*,
γ ∈ (N∪Σ)+
Examples
Towers of Hanoi: we can prove that any algorithm that solves this problem must have a
worst-case running time that is at least 2n − 1.
* List all permutations (all possible orderings) of n numbers.
P Class
The P in the P class stands for Polynomial Time. It is the collection of decision
problems(problems with a “yes” or “no” answer) that can be solved by a deterministic machine
in polynomial time.
Features:
1. The solution to P problems is easy to find.
2. P is often a class of computational problems that are solvable and tractable. Tractable
means that the problems can be solved in theory as well as in practice. But the problems
that can be solved in theory but not in practice are known as intractable.
NP Class
The NP in NP class stands for Non-deterministic Polynomial Time. It is the collection of
decision problems that can be solved by a non-deterministic machine in polynomial time.
Features:
1. The solutions of the NP class are hard to find since they are being solved by a non-
deterministic machine but the solutions are easy to verify.
2. Problems of NP can be verified by a Turing machine in polynomial time.
NP-hard class
An NP-hard problem is at least as hard as the hardest problem in NP and it is the class of the
problems such that every problem in NP reduces to NP-hard.
Features:
1. All NP-hard problems are not in NP.
2. It takes a long time to check them. This means if a solution for an NP-hard problem is
given then it takes a long time to check whether it is right or not.
3. A problem A is in NP-hard if, for every problem L in NP, there exists a polynomial-time
reduction from L to A.
NP-complete class
A problem is NP-complete if it is both NP and NP-hard. NP-complete problems are the hardest
problems in NP.
Features:
1. NP-complete problems are special as any problem in NP class can be transformed or
reduced into NP-complete problems in polynomial time.
2. If one could solve an NP-complete problem in polynomial time, then one could also solve
any NP problem in polynomial time.
Undecidable Problems –
The problems for which we can’t construct an algorithm that can answer the problem correctly in
finite time are termed as Undecidable Problems. These problems may be partially decidable but
they will never be decidable. That is there will always be a condition that will lead the Turing
Machine into an infinite loop without providing an answer at all.
Vertex Cover
A Vertex Cover of a graph G is a set of vertices such that each edge in G is incident to at least one
of these vertices.
The decision vertex-cover problem was proven NPC. Now, we want to solve the optimal version
of the vertex cover problem, i.e., we want to find a minimum size vertex cover of a given graph.
We call such vertex cover an optimal vertex cover C*.
The idea is to take an edge (u, v) one by one, put both vertices to C, and remove all the edges
incident to u or v. We carry on until all edges have been removed. C is a VC. But how good is C?
We can model the cities as a complete graph of n vertices, where each vertex represents a city.
If we assume the cost function c satisfies the triangle inequality, then we can use the following
approximate algorithm.
Given a graph G = (V, E) we have to find the Hamiltonian Circuit using Backtracking approach.
We start our search from any arbitrary vertex say 'a.' This vertex 'a' becomes the root of our implicit
tree. The first element of our partial solution is the first intermediate vertex of the Hamiltonian
Cycle that is to be constructed. The next adjacent vertex is selected by alphabetical order. If at any
stage any arbitrary vertex makes a cycle with any vertex other than vertex 'a' then we say that dead
end is reached. In this case, we backtrack one step, and again the search begins by selecting another
vertex and backtrack the element from the partial; solution must be removed. The search using
backtracking is successful if a Hamiltonian Cycle is obtained.
Example: Consider a graph G = (V, E) shown in fig. we have to find a Hamiltonian circuit using
Backtracking method.
Solution: Firstly, we start our search with vertex 'a.' this vertex 'a' becomes the root of our
implicit tree.
Next, we choose vertex 'b' adjacent to 'a' as it comes first in lexicographical order (b, c, d).