Download presentation

Presentation is loading. Please wait.

1
Complexity Issues Mark Allen Weiss: Data Structures and Algorithm Analysis in Java Lydia Sinapova, Simpson College

2
2 Complexity Issues Class P problems Class NP problems NP-complete problems Non-NP problems Decidability

3
3 Class P Problems Polynomial run time in the worst-case "tractable" problems Examples Simple sorting algorithms Advanced sorting algorithm Topological Sort Shortest Paths Min Spanning Trees

4
4 Class NP Problems NP-Problems: Problems for which there is no known polynomial-time algorithms, "intractable" problems NP means non-deterministically polynomial. If we have a candidate for a solution, we can verify it in polynomial time. The difficult part is to generate all possible candidates. Example: (the satisfiability problem) Given a boolean expression of n variables, find a set of variable assignments that satisfy the expression Obviously, P NP, but P NP (or P = NP) is an open question

5
5 NP-Complete Problems An NP-Complete problem is an NP problem with the property that any problem in NP can be reduced to it in polynomial time In 1971 Stephen Cook (currently working at the University of Toronto, Ontario) showed that the satisfiability problem is NP-complete by proving that every other NP problem could be transformed to it. http://www.cs.toronto.edu/DCS/People/Faculty/sacook.html

6
6 NP-Complete Problems Bin packing problem: How to pack or store objects of various sizes and shapes with a minimum of wasted space? Clique problem: A clique is a subset K of vertices in an undirected graph G such that every pair is joined by an edge in G. The problems are: Given a graph G, and an integer k, does G have a clique consisting of k vertices? Given a graph G, find a clique with as many vertices as possible. Knapsack problem: You have a knapsack with a given size and several objects with various sizes and values. The problem is how to fill your knapsack with these objects so that you have a maximum total value. Hamiltonian Cycle: a cycle that contains all nodes of the graph. Proving that a graph has a Hamiltonian cycle is a NP-complete problem.

7
7 NP-Complete Problems NP problems and non-NP problems: For NP problems, given a candidate for a solution, we can verify it in polynomial time. For non-NP problems, we cannot verify in polynomial time whether a candidate for a solution is a solution or not. Example: the problem to prove that a graph does not have a Hamiltonian cycle is a non-NP problem. NP-hard problems: NP-Complete, but not necessarily in NP class

8
8 Decidability Yes/no problems (decision problems) A decision problem is a question that has two possible answers yes or no. The question is about some input.

9
9 Examples of Yes/No Problems Given a graph G and a set of vertices K, is K a clique? Given a graph G and a set of edges M, is M a spanning tree? Given a set of axioms (boolean expressions) and an expression, is the expression provable under the axioms?

10
10 Decidable, semi-decidable, and undecidable problems A problem is decidable if there is an algorithm (P or NP) that says yes if the answer is yes, and no otherwise. A problem is semi-decidable if there is an algorithm that says yes if the answer is yes, however it may loop infinitely if the answer is no. A problem is undecidable if we can prove that there is no algorithm that will deliver an answer.

11
11 Example of semi-decidable problem Given a set of axioms, prove that an expression is true. Problem 1: Let the axioms be: A v B A v C ~B Prove A. To prove A we add ~A to the axioms. If A is true then ~A will be false and this will cause a contradiction - the conjunction of all axioms plus ~A will result in False (A v B) ~A = B B (A v C) = (B A) v (B C) B ~ B = False

12
12 Example of semi-decidable problem Problem 2: Let the axioms be: A v B A v C ~B Prove ~A. We add A and obtain: (A v C) A = A (A v B) A = A A ~B = A ~B (A ~B) (A v B) = A ~ B ….. This process will never stop, because the expressions we obtain will always be different from False

13
13 Example of undecidable problem The halting problem Let LOOP be a program that checks other programs for infinite loops: LOOP(P) stops and prints "yes" if P loops infinitely LOOP(P) enters an infinite loop if P stops What about LOOP(LOOP)? http://www.cgl.uwaterloo.ca/~csk/washington/halt.html

Similar presentations

© 2021 SlidePlayer.com Inc.

All rights reserved.

To make this website work, we log user data and share it with processors. To use this website, you must agree to our Privacy Policy, including cookie policy.

Ads by Google