Presentation is loading. Please wait.

Presentation is loading. Please wait.

Hard Problems Some problems are hard to solve.

Similar presentations


Presentation on theme: "Hard Problems Some problems are hard to solve."— Presentation transcript:

1 Hard Problems Some problems are hard to solve.
No polynomial time algorithm is known. E.g., NP-hard problems such as machine scheduling, bin packing, 0/1 knapsack. Is this necessarily bad? Data encryption relies on difficult to solve problems. Optimal scheduling of machines could save a lot of energy. Same for optimal truck loading. 0/1 knapsack problem has a pseudo-polynomial time dynamic programming solution.

2 Reminder: NP-hard Problems
Infamous class of problems for which no one has developed a polynomial time algorithm. That is, no algorithm whose complexity is O(nk) for any constant k is known for any NP-hard problem. The class includes thousands of real-world problems. Highly unlikely that any NP-hard problem can be solved by a polynomial time algorithm. NP-hard = non-deterministic polynomial-time hard (at least as hard as the hardest problems in NP) Given the answer, it can be verified in polynomial time. (quickly checkable) e.g. Subset sum problem is NP-complete [ (Slide copied from lec23)

3 Reminder: NP-hard Problems
Since even polynomial time algorithms with degree k > 3 (say) are not practical for large n, we must change our expectations of the algorithm that is used. Usually develop fast heuristics for NP-hard problems. Algorithm that gives a solution close to best. Approximation algorithms Runs in acceptable amount of time. LPT rule is a good heuristic for minimum finish time scheduling. (Slide copied from lec23)

4 NP (non-deterministic polynomial-time)
Source:

5 Satisfiability Problem
The permissible values of a boolean variable are true and false. The complement of a boolean variable x is denoted x. A literal is a boolean variable or the complement of a boolean variable. A clause is the logical or of two or more literals. Let x1, x2, x3, …, xn be n boolean variables.

6 Satisfiability Problem
Example clauses: x1+ x2 + x3 x4+ x7 + x8 x3+ x7 + x9 + x15 x2+ x5 A boolean formula (in conjunctive normal form CNF) is the logical and of m clauses. F = C1C2C3…Cm

7 Satisfiability Problem
F = (x1+ x2 + x3)( x4+ x7 + x8)(x2+ x5) F is true when x1, x2, and x4 (for e.g.) are true. Can set up a satisfiability instance in about 50,000 variables to crack DES.

8 Satisfiability Problem
A boolean formula is satisfiable iff there is at least one truth assignment to its variables for which the formula evaluates to true. Determining whether a boolean formula in CNF is satisfiable is NP-hard. Problem is solvable in polynomial time when no clause has more than 2 literals. Remains NP-hard even when no clause has more than 3 literals. Also in NP  NP-Complete (NPC)

9 Partition Problem Partition NP-hard. Also in NP  NP-Complete (NPC)
Partition n positive integers s1, s2, s3, …, sn into two groups A and B such that the sum of the numbers in each group is the same. [9, 4, 6, 3, 5, 1,8] A = [9, 4, 5] and B = [6, 3, 1, 8] NP-hard. Also in NP  NP-Complete (NPC)

10 Subset Sum Problem Does any subset of n positive integers s1, s2, s3, …, sn have a sum exactly equal to c? [9, 4, 6, 3, 5, 1,8] and c = 18 A = [9, 4, 5] NP-hard. Also in NP  NP-Complete

11 Traveling Salesperson Problem (TSP)
Let G be a weighted directed graph. A tour in G is a cycle that includes every vertex of the graph. TSP => Find a tour of shortest length. Problem is NP-hard.

12 Applications Of TSP Home city Visit city
Once a month the salesperson starts from home and visits each city in his/her territory once. When done, the salesperson returns home. The salesperson wishes to minimize time spent in this activity. Assuming that the time spent at each city is fixed, total time is minimized by minimizing travel time. So, a tour of minimum length is desired. Home city Visit city

13 Applications Of TSP Robot Station
During tennis practice, 2 persons play using a large number of balls. When done, The balls are to be collected by a robot (probably one of the players or an unfortunate relative). The ball locations are vertices of a graph. Inter-vertex distance is the distance the robot has to travel to get from one ball to the next (accounts for going around the net if necessary). The robot must visit each vertex, pick up the ball, and return to the base station in minimum time.

14 Applications Of TSP Manufacturing.
A robot arm is used to drill n holes in a metal sheet. Robot Station Time to drill the holes is fixed. The only variable is the time the robot spends moving from one hole location to the next and finally returning to its base. n+1 vertex TSP.

15 Difficult Problems Many require you to find either a subset or permutation that satisfies some constraints and (possibly also) optimizes some objective function. May be solved by organizing the solution space into a tree and systematically searching this tree for the answer.

16 Subset Problems Solution requires you to find a subset of n elements.
The subset must satisfy some constraints and possibly optimize some objective function. Examples. Partition. Subset sum. 0/1 Knapsack. Satisfiability (find subset of variables to be set to true so that formula evaluates to true). Scheduling 2 machines. Packing 2 bins.

17 Permutation Problems Solution requires you to find a permutation of n elements. The permutation must satisfy some constraints and possibly optimize some objective function. Examples. TSP. n-queens. Each queen must be placed in a different row and different column. Let queen i be the queen that is going to be placed in row i. Let ci be the column in which queen i is placed. c1, c2, c3, …, cn is a permutation of [1,2,3, …, n] such that no two queens attack.

18 Solution Space Set that includes at least one solution to the problem.
Subset problem. n = 2, {00, 01, 10, 11} n = 3, {000, 001, 010, 100, 011, 101, 110, 111} Solution space for subset problem has 2n members. Nonsystematic search of the space for the answer takes O(p2n) time, where p is the time needed to evaluate each member of the solution space.

19 Solution Space Permutation problem.
Solution space for a permutation problem has n! members. Nonsystematic search of the space for the answer takes O(pn!) time, where p is the time needed to evaluate a member of the solution space.


Download ppt "Hard Problems Some problems are hard to solve."

Similar presentations


Ads by Google