Tcom 018 N
Tcom 018 N
1
Tasks with time complexity theory
2
Measuring complexity
3
Worst-case analysis
4
Running Time or Time Complexity
of Turing machine
Let M be a deterministic Turing machine
that halts on all inputs.
5
t(n) time Turing machine
6
Asymptotic analysis for estimation of running
time of algorithm for large inputs
• The method is based upon considering only the
highest order term of the expression for the running
time of the algorithm, disregarding both the
coefficient of that term and any lower order terms,
because the highest order term dominates the other
terms on large inputs.
• Then the running time t is said to be asymptotically at
most the highest order term .
7
Big-O Notation
8
Formal Definition Big-O Notation
9
Example
Let f1( n) be the function 5n3 + 2n2 + 22n + 6.
Then, selecting the highest order term 5n3 and
disregarding its coefficient 5 gives f1( n) = O(n3).
• Verify that this result satisfies the formal
definition. Let c be 6 and n0 be 10.
• Then, 5n3 + 2n2 + 22n + 6 6 n3 for every
n 10.
10
Example (cont.)
11
Type of bounds
1. Polynomial bounds : Bounds are derived of
the form nc for c greater than 0, are called
polynomial bounds.
12
Small-o notation
13
Definition
14
The difference between the big-O and
small-o notations
The difference between the big-O and
small-o notations is analogous to the
difference between and <.
15
Example : Analyzing algorithms
16
Example : (cont.)
4. If 0s still remain after all the 1s have been
crossed off, or if 1s still remain after all the 0s
have been crossed off, reject. Otherwise, if
neither 0s nor 1s remain on the tape, accept."
17
Steps for simulation of string 0*1*
In stage 1, the machine scans across the tape to verify
that the input is of the form 0*1* .
• Performing this scan uses n steps. ( n represents the
length of the input).
• Repositioning the head at the left-hand end of the tape
uses another n steps.
• So the total used in this stage is 2n steps.
• This stage uses O(n) steps.
18
Steps (cont.)
In stages 2 and 3, the machine repeatedly scans the tape
and crosses off a 0 and 1 on each scan.
• Each scan uses O(n) steps.
• Because each scan crosses off two symbols, at most
n/2 scans can occur.
• So the total time taken by stages 2 and 3 is (n/2)O(n)
= O(n2 ) steps.
19
Steps (cont.)
In stage 4 the machine makes a single scan to decide
whether to accept or reject.
• The time taken in this stage is at most O(n).
• Thus the total time of M1 on an input of length n is
O(n) + O(n2) + O(n), or O(n2).
• Thus its running time is O(n2), which completes the
time analysis of this machine.
20
Time Complexity Class - TIME(t(n))
It is the collection of all languages that are decidable by
an O(t(n)) time deterministic Turing machine.
Where t: N → R+ be a function and n – length of input.
Formally
TIME(t(n)) = {L| L is a language decided by a O(t(n))
time deterministic Turing machine}.
Example:
For the language A = {0k 1 k | k 0}, analysis shows
that A TIME(n2) because M1 decides A in time O(n2)
and TIME(n2) contains all languages that can be decided
in O(n2) time.
21
Nondeterministic Time Complexity
Class - NTIME(t(n))
It is the collection of all languages that are
decidable by an O(t(n)) time non-deterministic
Turing machine.
Where t: N → R+ be a function and n – length of
input.
Formally
NTIME(t(n)) = {L| L is a language decided by a
O(t(n)) time nondeterministic Turing machine}.
22
Theorem
Let t(n) be a function, where t(n) n, n = length
of input. Then every t(n) time multi-tape Turing
machine has an equivalent O(t2(n)) time single-
tape Turing machine.
23
Proof (Idea)
• Convert any multi-tape TM into a single-tape
TM that simulates it.
• Show that simulating each step of the multi-
tape machine uses at most O(t(n)) steps on the
single-tape machine.
• Hence the total time used is O(t2(n)) steps.
24
The running time of a nondeterministic
Turing machine.
Let N be a nondeterministic Turing machine that
is a decider, all its computation branches halt on
all inputs.
• The running time of N is the function t: N →
N, where t (n) is the maximum number of steps
that N uses on any branch of its computation on
any input of length n.
25
Theorem
Let t(n) be a function, where t(n) n. Then every
t(n) time nondeterministic single-tape Turing
machine has an equivalent 2O(t(n)) time
deterministic single-tape Turing machine.
26
Proof:
27
Proof (cont.)
29
Proof (cont.)
30