Download presentation

Presentation is loading. Please wait.

Published byPatience Thornbrugh Modified over 4 years ago

2
Reducibility and NP-Completeness

3
COSC 3101B, PROF. J. ELDER 2 Computational Complexity Theory Computational Complexity Theory is the study of how much of a given resource (such as time, space, parallelism, algebraic operations, communication) is required to solve important problems.

4
COSC 3101B, PROF. J. ELDER 3 Classification of Problems Q. Which problems will we be able to solve in practice? A working definition. [Cobham 1964, Edmonds 1965, Rabin 1966] Those with polynomial-time algorithms. Yes Probably no Shortest pathLongest path Min cutMax cut 2-SAT3-SAT Matching3D-matching Primality testingFactoring Planar 4-colorPlanar 3-color Bipartite vertex coverVertex cover

5
COSC 3101B, PROF. J. ELDER 4 Tractable Problems We have generally studied tractable problems (solvable in polynomial time). Algorithm design patterns.Examples. –Greed.O(n log n) activity scheduling. –Divide-and-conquer. O(n log n) merge sort. –Dynamic programming.O(n log n) activity scheduling with profits. –Duality.O(n 3 ) bipartite matching.

6
COSC 3101B, PROF. J. ELDER 5 Intractable Problems There are other problems that provably require exponential-time. Examples: –Given a Turing machine, does it halt in at most k steps on any finite input? –Given a board position in an n-by-n generalization of chess, can black guarantee a win?

7
COSC 3101B, PROF. J. ELDER 6 Impossible Problems There are other problems that cannot be solved by any algorithm.

8
COSC 3101B, PROF. J. ELDER 7 The Halting Problem The halting problem is a particular decision problem: –Given a description of a program and a finite input, decide whether the program will halt or run forever on that input. A general algorithm to solve the halting problem for all possible program-input pairs cannot exist: The halting problem is undecidable.

9
COSC 3101B, PROF. J. ELDER 8 NP Completeness Bad news. Huge number of fundamental problems have defied classification for decades. Some good news. Using the technique of reduction, we can show that these fundamental problems are "computationally equivalent" and appear to be different manifestations of one really hard problem.

10
COSC 3101B, PROF. J. ELDER 9 Ingredients: Instances: The possible inputs to the problem. Solutions for Instance: Each instance has an exponentially large set of solutions. Cost of Solution: Each solution has an easy to compute cost or value. Optimization Problems

11
COSC 3101B, PROF. J. ELDER 10 Specification of an Optimization Problem Preconditions: The input is one instance. Postconditions: The output is one of the valid solutions for this instance with optimal cost. (minimum or maximum) Optimization Problems Eg: Given graph G, find biggest clique.

12
COSC 3101B, PROF. J. ELDER 11 An optimization problem Each solution is either valid or not (no cost) The output is Yes, it has an valid solution. No, it does not the solution is not returned Eg: Given graph and integer, does G have a clique of size k? Non-Deterministic Poly-Time Decision Problems (NP)

13
COSC 3101B, PROF. J. ELDER 12 Key: Given an instance I (= ) and a solution S (= subset of nodes) there is a poly-time alg Valid(I,S) to test whether or not S is a valid solution for I. Poly-time in |I| not in |S|. k=4 Valid Not Valid Non-Deterministic Poly-Time Decision Problems (NP)

14
COSC 3101B, PROF. J. ELDER 13 Which are more alike? Network Flow Graph Colouring Circuit Satisfiability Bipartite Matching Best known algorithm exponential time Polynomial time algorithm Non-Deterministic Poly Time Complete Similar structure

15
Reducibility

16
COSC 3101B, PROF. J. ELDER 15 A Graph Named “Gadget”

17
COSC 3101B, PROF. J. ELDER 16 K-COLORING A k-coloring of a graph is an assignment of one color to each vertex such that: –No more than k colors are used –No two adjacent vertices receive the same color A graph is called k-colorable iff it has a k-coloring

18
COSC 3101B, PROF. J. ELDER 17 Course Scheduling Problem Given the courses students want to take and the time slots available, schedule courses to minimize number of conflicts (Avoid scheduling two courses at the same time if a student wants to take both).

19
COSC 3101B, PROF. J. ELDER 18 K-CRAYOLA Problem: Given a graph G and a k, find a way to colour G with k colours. Rudich www.discretemath.com each node. Colour each node. Nodes with lines between them must have different colours.

20
COSC 3101B, PROF. J. ELDER 19 Schedule each course. Courses that conflict can’t be at same time. each node. Nodes with lines between them must have different colours. Colour each node. Nodes with lines between them must have different colours. Two problems that are cosmetically different, but substantially the same Two Different Problems

21
COSC 3101B, PROF. J. ELDER 20 Problems are the Same! Schedule each course. Courses that conflict can’t be at same time. each node. Nodes with lines between them must have different colours. Colour each node. Nodes with lines between them must have different colours. English Math Science course node can’t be scheduled at same time line between them scheduled time colour 1pm Mon 3pm Fri

22
COSC 3101B, PROF. J. ELDER 21 A CRAYOLA Question! Is Gadget 2-colorable? No: it contains a triangle!

23
COSC 3101B, PROF. J. ELDER 22 Is Gadget 3-colorable? A CRAYOLA Question! Yes!

24
COSC 3101B, PROF. J. ELDER 23 Given a graph G, how do we decide if it can be 2-colored? 2 CRAYOLAS PERSPIRATION; BRUTE FORCE: Try out all 2 n ways of 2 coloring G.

25
COSC 3101B, PROF. J. ELDER 24

26
COSC 3101B, PROF. J. ELDER 25

27
COSC 3101B, PROF. J. ELDER 26

28
COSC 3101B, PROF. J. ELDER 27 Given a graph G, what is a fast algorithm to decide if it can be 3- colored? 3 CRAYOLAS ????????

29
Let’s consider a completely different problem.

30
COSC 3101B, PROF. J. ELDER 29 k-CLIQUES A k-clique is a set of k nodes with all k(k-1)/2 possible edges between them.

31
COSC 3101B, PROF. J. ELDER 30 This graph contains a 4-clique

32
COSC 3101B, PROF. J. ELDER 31 Given an n-node graph G and a number k, how can you decide if G contains a k- clique? PERSPIRATION: Try out all n-choose-k possible locations for the k clique INSPIRATION: ????????

33
OK, how about a slightly different problem?

34
COSC 3101B, PROF. J. ELDER 33 INDEPENDENT SET An independent set is a set of vertices with no edges between them. This graph contains an independent set of size 3.

35
COSC 3101B, PROF. J. ELDER 34 Given an n-node graph G and a number k, how can you decide if G contains an independent set of size k? PERSPIRATION: Try out all n-choose-k possible locations for independent set INSPIRATION: ????????

36
One more completely different problem

37
COSC 3101B, PROF. J. ELDER 36 Combinational Circuits AND, OR, NOT, gates wired together with no feedback allowed (acyclic).

38
COSC 3101B, PROF. J. ELDER 37 Logic Gates NotAndOr

39
COSC 3101B, PROF. J. ELDER 38 Example Circuit

40
COSC 3101B, PROF. J. ELDER 39 CIRCUIT-SATISFIABILITY (decision version) Given a circuit with n-inputs and one output, is there a way to assign 0-1 values to the input wires so that the output value is 1 (true)?

41
COSC 3101B, PROF. J. ELDER 40 CIRCUIT-SATISFIABILITY (search version) Given a circuit with n-inputs and one output, find an assignment of 0-1 values to the input wires so that the output value is 1 (true), or determine that no such assignment exists.

42
COSC 3101B, PROF. J. ELDER 41 Satisfiable Circuit Example

43
COSC 3101B, PROF. J. ELDER 42 Satisfiable? No!

44
COSC 3101B, PROF. J. ELDER 43 Given a circuit, is it satisfiable? PERSPIRATION: Try out all 2 n assignments INSPIRATION: ????????

45
COSC 3101B, PROF. J. ELDER 44 We have seen 4 problems: coloring, clique, independent set, and circuit SAT. They all have a common story: A large space of possibilities only a tiny fraction of which satisfy the constraints. Brute force takes too long, and no feasible algorithm is known.

46
COSC 3101B, PROF. J. ELDER 45 CLIQUE / INDEPENDENT SET Two problems that are cosmetically different, but substantially the same

47
COSC 3101B, PROF. J. ELDER 46 Complement Of G Given a graph G, let G *, the complement of G, be the graph obtained by the rule that two nodes in G * are connected if and only if the corresponding nodes of G are not connected

48
COSC 3101B, PROF. J. ELDER 47 Example 3-Clique Independent set of size 3

49
COSC 3101B, PROF. J. ELDER 48 Reduction –Suppose you have a method for solving the k-clique problem. –How could it be used to solve the independent set problem?

50
COSC 3101B, PROF. J. ELDER 49 Or what if you have an Oracle? or·a·cle Pronunciation: 'or-&-k&l, 'är- Function: noun Etymology: Middle English, from Middle French, from Latin oraculum, from orare to speak 1 a : a person (as a priestess of ancient Greece) through whom a deity is believed to speak 2 a : a person giving wise or authoritative decisions or opinions

51
COSC 3101B, PROF. J. ELDER 50 Let G be an n-node graph. GIVEN: Clique Oracle BUILD: Indep. Set Oracle

52
COSC 3101B, PROF. J. ELDER 51 Let G be an n-node graph. GIVEN: Indep. Set Oracle BUILD: Clique Oracle

53
COSC 3101B, PROF. J. ELDER 52 Thus, we can quickly reduce clique problem to an independent set problem and vice versa. There is a fast method for one if and only if there is a fast method for the other.

54
COSC 3101B, PROF. J. ELDER 53 Given an oracle for circuit SAT, how can you quickly solve 3-colorability?

55
COSC 3101B, PROF. J. ELDER 54 V n (X,Y) Let V n be a circuit that takes an n-node graph X and an assignment Y of colors to these nodes, and verifies that Y is a valid 3-colouring of X. i.e., V n (X,Y)=1 iff Y is a 3-colouring of X. X is expressed as an n-choose-2 bit sequence. Y is expressed as a 2n bit sequence. Given n, we can construct V n in time O(n 2 ).

56
COSC 3101B, PROF. J. ELDER 55 Let G be an n-node graph. GIVEN: SAT Oracle G BUILD: 3- color Oracle V n (G,Y)

57
COSC 3101B, PROF. J. ELDER 56 Given an oracle for circuit SAT, how can you quickly solve k-clique?

58
COSC 3101B, PROF. J. ELDER 57 V n,k (X,Y) Let V n be a circuit that takes an n-node graph X and a subset of nodes Y, and verifies that Y is a k-clique X. I.e., V n (X,Y)=1 iff Y is a k-clique of X. X is expressed as an n choose 2 bit sequence. Y is expressed as an n bit sequence. Given n, we can construct V n,k in time O(n 2 ).

59
COSC 3101B, PROF. J. ELDER 58 Let G be an n-node graph. GIVEN: SAT Oracle BUILD: Clique Oracle V n,k (G,Y)

60
COSC 3101B, PROF. J. ELDER 59 Given an oracle for 3-colorability, how can you quickly solve circuit SAT?

61
COSC 3101B, PROF. J. ELDER 60 Reducing Circuit-SAT to 3-Colouring Goal: map circuit to graph that is 3-colourable only if circuit is satisfiable. How do we represent a logic gate as a 3-colouring problem?

62
COSC 3101B, PROF. J. ELDER 61 X Y Output Example X and Y and Output are boolean variables in circuit. Without loss of generality, map truth values to colours, e.g. 0 red 1 green Add base colour for encoding purposes, e.g. blue. X Y

63
COSC 3101B, PROF. J. ELDER 62 X Y Output Example Note that in a valid 3- colouring, this node cannot have the same colour as X, Y or Output. Thus, without loss of generality, we can assign it the base colour, blue. X Y

64
COSC 3101B, PROF. J. ELDER 63 X Y Output Example Now suppose we fix this node to represent false. X Y

65
COSC 3101B, PROF. J. ELDER 64 X Y Output Example F Now suppose we fix this node to represent false. X Y

66
COSC 3101B, PROF. J. ELDER 65 Example T F X Y Output Now build a truth table for (X, Y, Output). What if X=Y=0? X Y

67
COSC 3101B, PROF. J. ELDER 66 Example T F X Y Output Now build a truth table for (X, Y, Output). What if X=Y=0? X Y

68
COSC 3101B, PROF. J. ELDER 67 Example T F X Y Output Now build a truth table for (X, Y, Output). What if X=Y=0? X Y

69
COSC 3101B, PROF. J. ELDER 68 Example T F X Y Output Now build a truth table for (X, Y, Output). What if X=Y=0? X Y

70
COSC 3101B, PROF. J. ELDER 69 Example T F X Y Output Thus (X,Y)=0 Output=0 X Y

71
COSC 3101B, PROF. J. ELDER 70 Example T F X Y Output Conversely, what if Output=0? X Y

72
COSC 3101B, PROF. J. ELDER 71 Example T F X Y Output Conversely, what if Output=0? X Y

73
COSC 3101B, PROF. J. ELDER 72 Example T F X Y Output Conversely, what if Output=0? X Y

74
COSC 3101B, PROF. J. ELDER 73 Example T F X Y Output Conversely, what if Output=0? X Y

75
COSC 3101B, PROF. J. ELDER 74 Example T F X Y Output Thus Output=0 X=Y=0. X Y

76
COSC 3101B, PROF. J. ELDER 75 Example T F X Y Output XY FFF FTT TFT TTT What type of gate is this? An OR gate! X Y

77
End of Final Lecture Nov 29, 2007

78
COSC 3101B, PROF. J. ELDER 77 TF X What type of gate is this? A NOT gate! Output X

79
COSC 3101B, PROF. J. ELDER 78 OR NOT xy z x y z

80
COSC 3101B, PROF. J. ELDER 79 OR NOT xy z x y z Satisfiability of this circuit = 3-colorability of this graph

81
COSC 3101B, PROF. J. ELDER 80 Let C be an n-input circuit. GIVEN: 3-color Oracle C BUILD: SAT Oracle Graph composed of gadgets that mimic the gates in C

82
COSC 3101B, PROF. J. ELDER 81 Formal Statement There is a polynomial-time function f such that: C is satisfiable f(C) is 3 colorable

83
COSC 3101B, PROF. J. ELDER 82 4 Problems All Equivalent If you can solve one quickly then you can solve them all quickly: Circuit-SAT Clique Independent Set 3 Colorability

84
COSC 3101B, PROF. J. ELDER 83

85
COSC 3101B, PROF. J. ELDER 84

86
COSC 3101B, PROF. J. ELDER 85

87
COSC 3101B, PROF. J. ELDER 86

88
COSC 3101B, PROF. J. ELDER 87

89
COSC 3101B, PROF. J. ELDER 88

90
COSC 3101B, PROF. J. ELDER 89

91
COSC 3101B, PROF. J. ELDER 90

92
COSC 3101B, PROF. J. ELDER 91

93
COSC 3101B, PROF. J. ELDER 92

94
COSC 3101B, PROF. J. ELDER 93

95
COSC 3101B, PROF. J. ELDER 94

96
COSC 3101B, PROF. J. ELDER 95

97
COSC 3101B, PROF. J. ELDER 96

98
COSC 3101B, PROF. J. ELDER 97

99
COSC 3101B, PROF. J. ELDER 98

100
COSC 3101B, PROF. J. ELDER 99

101
COSC 3101B, PROF. J. ELDER 100

Similar presentations

Presentation is loading. Please wait....

OK

When you see… Find the zeros You think….

When you see… Find the zeros You think….

© 2018 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