Slide phân tích và thiết kế giải thuật chap7completeness problems

25 7 0
Slide phân tích và thiết kế giải thuật chap7completeness problems

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

Thông tin tài liệu

.c om Chapter NP-Completeness Problems th NP-Completeness an co ng Deterministic and Nondeterministic PolynomialTime Algorithms du o ng Cook’s Theorem u Some NP-Complete Problems cu Some Approaches to cope with NP-Complete Problems CuuDuongThanCong.com https://fb.com/tailieudientucntt .c om Whether or not an efficient algorithm might exist For many problems we have several efficient algorithms to solve • However, many problems arise in practice which not have such efficient solving algorithms • For a large class of problems we can’t even tell whether or not an efficient algorithm might exist cu u du o ng th an co ng • CuuDuongThanCong.com https://fb.com/tailieudientucntt Easy and hard problems A great deal of research has been done in this area and lend to the development of mechanisms by which new problems can be classified as being as difficult as old problems • Sometimes, the line between “easy” and “hard” problems is only simple Example: „ Easy: Is there a path from x to y with weight ≤ M? „ Hard: Is there a path from x to y with weight ≥M? Problem - BFS – in linear time Problem – in exponential time cu u du o ng th an co ng c om • CuuDuongThanCong.com https://fb.com/tailieudientucntt .c om Deterministic and Nondeterministic Polynomial-Time Algorithms co ng P: The set of all problems that can be solved by deterministic algorithms in polynomial time cu u du o ng th an Deterministic: at any time, whatever the algorithm is doing, there is only one thing that it could next Example: Sorting by insertion belongs to P since its time is proportional to N2 CuuDuongThanCong.com https://fb.com/tailieudientucntt Nondeterminism cu u du o ng th an co ng c om One way to extend the power of a computer is to endow it with the power of non-determinism Non-determinism: when an algorithm is faced with a choice of several options, it has the power to “guess” the right one Nondeterministic algorithm Example: Let A be an unsorted set of positive integers An nondeterministic algorithm NSORT(A, n) sorts the numbers into ascending order and then outputs them in that order CuuDuongThanCong.com https://fb.com/tailieudientucntt ng Function choice(1:n) can choose one of the correct position in the range from to n cu u du o ng th an co // An array B is used as temporary array procedure NSORT(A,n) // sort n positive integers // begin for i:= to n B[i]:= 0; // guessing stage for i:= to n begin j := choice(1:n); if B[j] then failure else B[j]:= A[i] end // verification stage for i:= to n-1 if B[i] > B[i+1] then failure; print(B); success end; c om An example of nondeterministic algorithm CuuDuongThanCong.com https://fb.com/tailieudientucntt An example of nondeterministic algorithm (cont.) cu u du o ng th an co ng c om A deterministic interpretation of a nondeterministic algorithm can be made by allowing unbounded parallelism in computation Each time a choice to be made, the algorithm makes several copies of itself One copy is made for each of the possible choice Thus, many copies are executing at the same time - The first copy to reach a successful completion terminates all other computation - If a copy reaches a failure completion then only that copy of the algorithm terminates CuuDuongThanCong.com https://fb.com/tailieudientucntt .c om Nondeterministic algorithm cu u du o ng th an co ng In fact, a nondeterministic machine does not make any copies of an algorithm every time a choice to be made Instead, it has the ability to select the “correct” element from a set of allowable choices every time a choice is to be made A “correct” element is defined relative to a shortest sequence of choices that leads to a successful termination In case there is no sequence of choices leading to a successful termination, we shall assume that the algorithm terminates in one unit of time with output “unsuccessful computation” CuuDuongThanCong.com https://fb.com/tailieudientucntt Nondeterministic algorithm (cont.) an co ng c om Note: ‰ The success and failure signals are equivalent to a stop statement in a deterministic algorithm ‰ The complexity of NSORT is O(n) cu u du o ng th NP: the set of all problems that can be solved by nondeterministic algorithms in polynomial time Example : “Is there a longest path from vertex x to vertex y in a graph” is an NP problem CuuDuongThanCong.com https://fb.com/tailieudientucntt .c om Circuit satisfiability problem ng th an co ng Given a logical formula of the form (x1 + x3 + x5)*(x1+ ~x2 + x4)*(~x3 + x4 +x5)* (x2 + ~x3 + x5) where the xi ‘s represent Boolean variable (true or false), “+” represents OR, “*” represents AND, and ~ represents NOT cu u du o The CSP problem is to determine whether or not there exists an assigment of truth values to the variables that makes the formula true CSP is an NP problem Note: P is a subset of NP 10 CuuDuongThanCong.com https://fb.com/tailieudientucntt ng co cu u du o ng th an procedure EVAL(E, n) boolean x[n]; begin for i:= to n x[i] := choice(true, false) endfor; if (E is true) then success else failure end EVAL; c om Nondeterministic algorithm for CSP problem 11 CuuDuongThanCong.com https://fb.com/tailieudientucntt .c om NP-Completeness th an co ng There is a list of problems that are known to belong to NP but might or might not belong to P (That is, they are easy to solve on a non-deterministic machine but, no one has been able to find an efficient algorithm on a conventional machine for any of them) cu u du o ng These problems has an additional property: “If any of these problems can be solved in polynomial time on a deterministic machine, then so can all problems in NP.” 12 CuuDuongThanCong.com https://fb.com/tailieudientucntt .c om Such problems are said to be NP-complete an co ng Figure 6.1 th NP-complete P cu u du o ng NP 13 CuuDuongThanCong.com https://fb.com/tailieudientucntt th ng du o u cu • an co • NP-complete problems form a subset of the most difficult problems in NP The primary tool used to prove that problems are NPcomplete uses the idea of polynomial reducibility Any algorithm to solve a new problem in NP can be used to solve some known NP-complete problem by the following process transform any instance of the known NP-complete problem to an instance of the new problem, solve the problem using the given algorithm, then transform the solution back to a solution of the NP-complete problem ng • c om Polynomial reducibility 14 CuuDuongThanCong.com https://fb.com/tailieudientucntt Polynomial reducibility (cont.) co ng c om To prove that a problem in NP is NP-complete, we need only show that some known NP-complete problem is polynomial reducible to it du o ng th an Definition: Let L1 and L2 be problems L1 reduces to L2, (also written L1 α L2) if and only if there is a way to transform L1 to L2 such that any deterministic algorithm that solves L2 in polynomial time can be used to solve L1 cu u The transformation must be done in polynomial time 15 CuuDuongThanCong.com https://fb.com/tailieudientucntt Polynomial reducibility (cont.) an co ng c om To prove that a problem L is NP-complete, we need to prove that: L belongs to NP Some known NP-complete problem is polynomially reducible to L cu u du o ng th Example: Given two following problems „ Traveling Salesman Problem: Given a set of cities and distances between a pairs, find a tour of all the cities of distance less than M „ Hamilton Cycle Problem: Given a graph, find a simple cycle that includes all the vertices 16 CuuDuongThanCong.com https://fb.com/tailieudientucntt Polynomial reducibility (cont.) th an co ng c om Suppose we know the HCP is NP-complete and wish to determine whether or not the TSP is also NP-complete Any algorithm for solving the TSP can be used to solve the HCP, through the following reduction: Given a instance of of the HCP (a graph), construct an instance of the TSP as follows: ng • for cities for the TSP, use the set of vertices in the graph; cu u du o • for distances between each pair of cities, uses if there is an edge between the corresponding vertices in the graph, if there is no edge Then use the algorithm for the TSP to find a tour of distance ≤ N (N the number of vertices in the graph) The tour corresponds precisely to the Hamilton cycle 17 CuuDuongThanCong.com https://fb.com/tailieudientucntt Polynomial reducibility (cont.) c om That is HCP reduces to TSP, so the NP-completeness of HCP implies the NP-completeness of TSP an co ng The reduction of HCP to TSP is relative simple because the problems are so similar du o ng th Actually, polynomial reductions can be quite complicated and can connect problems which seem to be quite dissimilar cu u Example: It is possible to reduce the satisfiability problem to HCP How? 18 CuuDuongThanCong.com https://fb.com/tailieudientucntt Cook’s Theorem th an co ng c om But: How was the first problem proven to be NP-complete? S.A Cook (1971) gave a direct proof that CSP (Circurt Satisfiability Problem) is NP-complete “If there is a polynomial time algorithm for satisfiability problem, then all problems in NP can be solved in polynomial time” cu u du o ng The proof is extremely complicated but it is based on a general purpose computer known as a Turing machine 19 CuuDuongThanCong.com https://fb.com/tailieudientucntt Some NP-Complete Problems co ng c om Thousands of diverse problems are known to be NPcomplete Of course, the list begins with satisfiability problem and includes TSP and Hamilton-cycle problem, as well as longest-path th an The following additional problems are representative: du o ng - Partition: Given a set of integers, can they be divided into two sets whose sums are equal? cu u - Integer linear programming: Given a linear problem, is there a solution in integers? 20 CuuDuongThanCong.com https://fb.com/tailieudientucntt cu u du o ng th an co ng c om - Multiprocessor scheduling: Given a deadline and a set of tasks of varying length to be performed on two identical processors, can the tasks be arranged so that the deadline is met? - VERTEX COVER: Given a graph and an integer N, is there a set of fewer than N vertices which touched all the edges? - BIN PACKING: We are given n objects which have to be placed in bins of equal capacity L Object i requires li units of bin capacity The objective is to determine the minimum number of bins needed to accommodate all n objects 21 CuuDuongThanCong.com https://fb.com/tailieudientucntt P ≠ NP ? ng c om These and many related problems have important natural practical applications th an co The fact that no good algorithm has been found for any of these problems is surely strong evident that P ≠ NP? cu u du o ng Whether or not P= NP, the practical fact is that we have at present no algorithms guaranteed to solve any of the NPcomplete problems efficiently 22 CuuDuongThanCong.com https://fb.com/tailieudientucntt .c om Some Approaches to cope with NP-Complete Problems ng Use approximation algorithm that finds not the best solution but a near-optimal solution th an co Based on “average-time” performance, develop an algorithm that finds the solution in some cases, but does not necessarily work in all cases du o ng Use with “efficient” exponential algorithms, for example, backtracking algorithm cu u Invent heuristics and add it to the algorithm to improve the performance of the algorithm Apply metaheuristics 23 CuuDuongThanCong.com https://fb.com/tailieudientucntt Heuristic and meta heuristic cu u du o ng th an co ng c om ƒ Heuristics is knowledge in a specific problem that can be used to guide the search process in finding a solution of an algorithm Thank to this heuristics, the algorithm becomes more efficient ƒ Metaheuristics is a kind of more general heuristics which can be used for solving several kinds of problems ƒ Recently, meta heuristics is an active research field with the introduction of many popular metaheuristics, such as: - genetic algorithm - simulated annealing - Tabu search - ACO - etc 24 CuuDuongThanCong.com https://fb.com/tailieudientucntt Contribution of the theory of NP-completeness cu u du o ng th an co ng c om There are several NP-complete problems in the following fields: ‰ numerical analysis, ‰ sorting and searching, ‰ string processing, ‰ geometry modeling ‰ graph processing ‰ image processing ‰ data mining The most important practical contribution of the theory of NP-completeness is that: it provides a mechanism to discover a new problem from any of these diverse areas is “easy” or “hard”” 25 CuuDuongThanCong.com https://fb.com/tailieudientucntt ... exist For many problems we have several efficient algorithms to solve • However, many problems arise in practice which not have such efficient solving algorithms • For a large class of problems we... and hard problems A great deal of research has been done in this area and lend to the development of mechanisms by which new problems can be classified as being as difficult as old problems •... them) cu u du o ng These problems has an additional property: “If any of these problems can be solved in polynomial time on a deterministic machine, then so can all problems in NP.” 12 CuuDuongThanCong.com

Ngày đăng: 06/12/2021, 14:33

Mục lục

  • Whether or not an efficient algorithm might exist

  • Easy and hard problems

  • 1. Deterministic and Nondeterministic Polynomial-Time Algorithms

  • An example of nondeterministic algorithm

  • 5. Some Approaches to cope with NP-Complete Problems

  • Heuristic and meta heuristic

  • Contribution of the theory of NP-completeness

Tài liệu cùng người dùng

Tài liệu liên quan