1 / 24

SUBSET-SUM

SUBSET-SUM. Instance: A set of numbers denoted S and a target number t . Problem: To decide if there exists a subset Y S , s.t  yY y=t. 13. 16. 8. 21. 1. 3. 6. 11. SUBSET-SUM is in NP. On input S,t : Guess Y S Accept iff  yY y=t .

genica
Download Presentation

SUBSET-SUM

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. SUBSET-SUM Instance: A set of numbers denoted S and a target number t. Problem: To decide if there exists a subset YS, s.t yYy=t. 13 16 8 21 1 3 6 11

  2. SUBSET-SUM is in NP On input S,t: • Guess YS • Accept iff yYy=t. The length of the certificate: O(n) (n=|S|) Time complexity: O(n)

  3. t SUBSET-SUM is NP-Complete Proof: We’ll show 3SATpSUBSET-SUM.

  4. Examples SUBSET-SUM … because 2+8=10 … because 11 cannot be made out of {2,4,8}

  5. Reducing 3SAT to SubSet Sum • Proof idea: • Choosing the subset numbers from the set S corresponds to choosing the assignments of the variables in the 3CNF formula. • The different digits of the sum correspond to the different clauses of the formula. • If the target t is reached, a valid and satisfying assignment is found.

  6. Subset Sum clause: 3CNF formula: Make the number table, and the ‘target sum’ t dummies +

  7. Reducing 3SAT to SubSet Sum • Let 3CNF with k clauses and  variables x1,…,x. • Create a Subset-Sum instance <S,t> by: 2+2k elements of S = {y1,z1,…,y,z,g1,h1,…,gk,hk} • yj indicates positive xj literals in clauses • zj indicates negated xj literals in clauses • gj and hj are dummies • and

  8. Subset Sum Note 1: The “1111” in the target forces a proper assignment of the xi variables. Note 2: The target “3333” is only possible if each clause is satisfied. (The dummies can add maximally 2 extra.)

  9. Subset Sum + is a satisfying assignment

  10. Subset Sum + is not a satisfying assignment

  11. Proof 3SAT P Subset Sum • For every 3CNF , take target t=1…13…3 and the corresponding set S. • If 3SAT, then the satisfying assignment defines a subset that reaches the target. • Also, the target can only be obtained via a set that gives a satisfying assignment for .

  12. Finding the Solution • If the decision problem Subset-Sum is solvable in polynomial time, then we can also find the subset that reaches the target in poly-time. • How? • By asking smart questions about several variants of the problem. • That way, we can determine which variables xi are involved in the solution.

  13. but this graph has no Hamiltonian path this graph has a Hamiltonian path Directed Hamiltonian Path • Given a directed graph G, does there exist a Hamiltonian path, which visits all nodes exactly once? • Two Examples:

  14. 3SAT to Hamiltonian Path • Proof idea: Given a 3CNF , make a graph G such that • … a Hamiltonian path is possible if and only if there is a zig-zag path through G, • … where the directions (zig or zag) determine the assignments (true or false) of the variables x1,…,xL of .

  15. s For every i, “Zig” means xi=True … while “Zag” means xi=False t “Zig-Zag Graphs” There are 2L different Hamiltonian paths from s to the target t.

  16. Accessing the Clauses If  has K clauses,  = C1 Ck, then xi has K “hubs”: Idea: Make K extra nodes Cj that can only be visited via the hub-path that defines an assignment of xi which satisfies the clause (using zig/zag = T/F). stands for

  17. If then xi=True=“zig” reaches node Cj If then xi=False=“zag” reaches node Cj Connecting the Clauses Let the clause Cj contain xi:

  18. Proof 3SAT P HamPath • Given a 3CNF (x1,…,xL) with K clauses • Make graph G with a zig/zag levels for every xi • Connect the clauses Cj via the proper “hubs” • If SAT, then the satisfying assignment defines a Hamiltonian path, and vice versa.

  19. Example 4 variables… 4 clauses… Clauses connected via zig-zag “hubs”

  20. Example assignment… …satifies all four clauses; hence it defines a Hamiltonian Path

  21. Example assignment… …does not satify first clause; hence the path misses the C1 node

  22. More on Hamiltonian Path • Useful for proving NP-completeness of “optimal routing problems” • Typical example: NP-completeness of “Traveling Salesman Problem” • Issue of directed versus undirected graphs

  23. Forcing Directions Given a directed graph with s,x1,…,xk,t Replace s with sout, the t with tin ,and every xi with the triplet “xi,in—xi,mid —xi,out” Redraw the original directed edges with edges going from out-nodes to in-nodes. If and only if the directed graph has a HamPath from s to t, then so has this graph.

  24. becomes becomes xin yin xin yin xmid ymid xmid ymid sout sout xout yout xout yout Example: Directions x x s s y y “Undirected HamPath” is NP-complete

More Related