Vous êtes sur la page 1sur 3

Deterministic algorithm

In computer science, a deterministic algorithm is an algorithm which, in informal terms, behaves


predictably. Given a particular input, it will always produce the same output, and the underlying
algorithm will always pass through the same sequence of states.
Example: Binary search, Backtracking, Branch and Bound which will give u optimal solutions
always.
Nondeterministic algorithm
Is an algorithm that can exhibit different behaviors on different runs, as opposed to a
deterministic algorithm. There are several ways an algorithm may behave differently from run to
run.
Examples: 1. 0/1 Knapsack problem using greedy technique, where we wont get best solution
always.
2. Suppose we have a finite collection of things (say, 300 student exams) that we need to sort
(say, by student number).
One algorithm to do this (called merge sort):

split the collection in two approximately equal parts

sort the two halves with merge sort (i.e. recursively)

merge the results

Items can only be uniquely sorted if the sorting criterion chosen always defines a total order; e.g.
student numbers are expected to be unique, but if we sort exams by name and two students
happen to have the same name, the order in which their exams get sorted is left undefined. In
such cases, merge sort will always arrive at one of the possible valid orderings, but which one is
left unspecifiedhence it is nondeterministic.
Decision problem: A question with a yes or no answer.
Polynomial Time Algorithm. (P class)
An algorithm is said to be solvable in polynomial time if the number of steps required to
complete the algorithm for a given input is
for some nonnegative integer , where is the
complexity of the input. Polynomial-time algorithms are said to be "fast." Most familiar
mathematical operations such as addition, subtraction, multiplication, and division, as well as
computing square roots, powers, and logarithms, can be performed in polynomial time.
A decision problem that can be solved in polynomial time (i.e O (n k) ). That is, given an instance
of the problem, the answer yes or no can be decided in polynomial time.

Example: Given a graph connected G, can its vertices be colored using two colors so that no
edge is monochromatic. Algorithm: start with an arbitrary vertex, color it red and all of its
neighbors blue and continue. Stop when you run our of vertices or you are forced to make an
edge have both of its endpoints be the same color.
Nondeterministic Polynomial Time Algorithm (NP) : A decision problem where instances of
the problem for which the answer is yes have proofs that can be verified in polynomial time. This
means that if someone gives us an instance of the problem and a certificate (sometimes called a
witness) to the answer being yes, we can check that it is correct in polynomial time.
Example: Integer factorization is NP. This is the problem that given integers n and m, is there an
integer f with 1 < f < m such that f divides n (f is a small factor of n)? This is a decision problem
because the answers are yes or no. If someone hands us an instance of the problem (so they hand
us integers n and m) and an integer f with 1 < f < m and claim that f is a factor of n (the
certificate) we can check the answer in polynomial time by performing the division n / f.
NP complete
Generally this is a class of problems that are so difficult that even the best solutions cannot
consistently determine their solutions in an efficient way. Specifically, NP Complete problems
can only possibly be solved in polynomial time using a nondeterministic Turing machine (Turing
machine is a computer, capable of making guesses and checking them in polynomial time).
Problems such as weather prediction, how to fill a box with odd-sized objects, and the Traveling
Salesman problem fall into the realm of NP Complete problems. Because of the problem with
finding the best solution, programs are often developed to find a usually reasonable solution.
The NP-Complete problems are an interesting class of problems whose status is unknown. No
polynomial-time algorithm has been discovered for an NP-Complete problem

Reduction or transformation
A problem P can be reduced to another problem Q if any instance of P can be rephrased to an
instance of Q, the solution to which provides a solution to the instance of P
This rephrasing is called a transformation.
If P reduces in polynomial time to Q, P is no harder to solve than Q.
NP Hard

NP-hard (non-deterministic polynomial-time hard), in computational complexity theory, is a


class of problems that are, informally, "at least as hard as the hardest problems in NP". A
problem H is NP-hard if and only if there is an NP-complete problem L that is polynomial time
Turing-reducible to H (i.e., LTH). In other words, L can be solved in polynomial time by an
oracle machine with an oracle for H. Informally, we can think of an algorithm that can call such
an oracle machine as a subroutine for solving H, and solves L in polynomial time, if the
subroutine call takes only one step to compute. NP-hard problems may be of any type: decision
problems, search problems, or optimization problems.
NP hard problems are even harder than the NP-complete problems. Note that NP-hard problems
do not have to be in NP (they do not have to be decision problems). The precise definition here is
that a problem X is NP-hard if there is an NP-complete problem Y such that Y is reducible to X
in polynomial time. But since any NP-complete problem can be reduced to any other NPcomplete problem in polynomial time, all NP-complete problems can be reduced to any NP-hard
problem in polynomial time. Then if there is a solution to one NP-hard problem in polynomial
time, there is a solution to all NP problems in polynomial time.
The halting problem is the classic NP-hard problem. This is the problem that given a program P
and input I, will it halt?(i.e ever terminate, or enter an infinite loop?) This is a decision problem
but it is not in NP. Halting problem cannot be solved by any computer, no matter how much time
is provided.

Vous aimerez peut-être aussi