算法设计与分析算法设计与分析 (11).ppt

上传人:刘静 文档编号:83298937 上传时间:2023-03-30 格式:PPT 页数:21 大小:357KB
返回 下载 相关 举报
算法设计与分析算法设计与分析 (11).ppt_第1页
第1页 / 共21页
算法设计与分析算法设计与分析 (11).ppt_第2页
第2页 / 共21页
点击查看更多>>
资源描述

《算法设计与分析算法设计与分析 (11).ppt》由会员分享,可在线阅读,更多相关《算法设计与分析算法设计与分析 (11).ppt(21页珍藏版)》请在taowenge.com淘文阁网|工程机械CAD图纸|机械工程制图|CAD装配图下载|SolidWorks_CaTia_CAD_UG_PROE_设计图分享下载上搜索。

1、1Chapter 8NP and ComputationalIntractabilitySlides by Kevin Wayne.Copyright 2005 Pearson-Addison Wesley.All rights reserved.2Algorithm Design Patterns and Anti-PatternsAlgorithm design patterns.Ex.nGreed.O(n log n)interval scheduling.nDivide-and-conquer.O(n log n)FFT.nDynamic programming.O(n2)edit d

2、istance.nReductions.Algorithm design anti-patterns.nNP-completeness.O(nk)algorithm unlikely.nPSPACE-completeness.O(nk)certification algorithm unlikely.nUndecidability.No algorithm possible.8.1 Polynomial-Time Reductions4Classify Problems According to Computational RequirementsQ.Which problems will w

3、e be able to solve in practice?A working definition.Cobham 1964,Edmonds 1965,Rabin 1966 Those with polynomial-time algorithms.YesProbably noShortest pathLongest pathMin cutMax cut2-SAT3-SATMatching3D-matchingPrimality testingFactoringPlanar 4-colorPlanar 3-colorBipartite vertex coverVertex cover5Cla

4、ssify ProblemsDesiderata.Classify problems according to those that can be solved in polynomial-time and those that cannot.Huge number of fundamental problems have defied classification for decades.This chapter.Show that these fundamental problems are computationally equivalent.6Polynomial-Time Reduc

5、tionDesiderata.Suppose we could solve X in polynomial-time.What else could we solve in polynomial time?Reduction.Problem X polynomial reduces to problem Y if arbitrary instances of problem X can be solved using:nPolynomial number of standard computational steps,plusnPolynomial number of calls to ora

6、cle that solves problem Y.Notation.X P Y.Remarks.nWe pay for time to write down instances sent to black box instances of Y must be of polynomial size.nNote:Cook reducibility.7Polynomial-Time ReductionPurpose.Classify problems according to relative difficulty.Design algorithms.If X P Y and Y can be s

7、olved in polynomial-time,then X can also be solved in polynomial time.Establish intractability.If X P Y and X cannot be solved in polynomial-time,then Y cannot be solved in polynomial time.Establish equivalence.If X P Y and Y P X,we use notation X P Y.Reduction By Simple EquivalenceBasic reduction s

8、trategies.Reduction by simple equivalence.Reduction from special case to general case.Reduction by encoding with gadgets.9Independent SetINDEPENDENT SET:Given a graph G=(V,E)and an integer k,is there a subset of vertices S V such that|S|k,and for each edge at most one of its endpoints is in S?Ex.Is

9、there an independent set of size 6?Yes.Ex.Is there an independent set of size 7?No.independent set10Vertex CoverVERTEX COVER:Given a graph G=(V,E)and an integer k,is there a subset of vertices S V such that|S|k,and for each edge,at least one of its endpoints is in S?Ex.Is there a vertex cover of siz

10、e 4?Yes.Ex.Is there a vertex cover of size 3?No.vertex cover11Vertex Cover and Independent SetClaim.VERTEX-COVER P INDEPENDENT-SET.Pf.We show S is an independent set iff V S is a vertex cover.vertex coverindependent set12Vertex Cover and Independent SetClaim.VERTEX-COVER P INDEPENDENT-SET.Pf.We show

11、 S is an independent set iff V S is a vertex cover.nLet S be any independent set.nConsider an arbitrary edge(u,v).nS independent u S or v S u V S or v V S.nThus,V S covers(u,v).nLet V S be any vertex cover.nConsider two nodes u S and v S.nObserve that(u,v)E since V S is a vertex cover.nThus,no two n

12、odes in S are joined by an edge S independent set.Reduction from Special Case to General CaseBasic reduction strategies.Reduction by simple equivalence.Reduction from special case to general case.Reduction by encoding with gadgets.14Set CoverSET COVER:Given a set U of elements,a collection S1,S2,.,S

13、m of subsets of U,and an integer k,does there exist a collection of k of these sets whose union is equal to U?Ex:U=1,2,3,4,5,6,7 k=2S1=3,7S4=2,4S2=3,4,5,6S5=5S3=1S6=1,2,6,715SET COVERU=1,2,3,4,5,6,7 k=2Sa=3,7Sb=2,4Sc=3,4,5,6Sd=5Se=1Sf=1,2,6,7Vertex Cover Reduces to Set CoverClaim.VERTEX-COVER P SET-

14、COVER.Pf.Given a VERTEX-COVER instance G=(V,E),k,we construct a set cover instance whose size equals the size of the vertex cover instance.Construction.nCreate SET-COVER instance:k=k,U=E,Sv=e E:e incident to v nSet-cover of size k iff vertex cover of size k.adbefcVERTEX COVERk=2e1 e2 e3 e5 e4 e6 e7

15、8.2 Reductions via GadgetsBasic reduction strategies.Reduction by simple equivalence.Reduction from special case to general case.Reduction via gadgets.17Ex:Yes:x1=true,x2=true x3=false.Literal:A Boolean variable or its negation.Clause:A disjunction of literals.Conjunctive normal form:A propositional

16、formula that is the conjunction of clauses.SAT:Given CNF formula,does it have a satisfying truth assignment?3-SAT:SAT where each clause contains exactly 3 literals.Satisfiability183 Satisfiability Reduces to Independent SetClaim.3-SAT P INDEPENDENT-SET.Pf.Given an instance of 3-SAT,we construct an i

17、nstance(G,k)of INDEPENDENT-SET that has an independent set of size k iff is satisfiable.Construction.nG contains 3 vertices for each clause,one for each literal.nConnect 3 literals in a clause in a triangle.nConnect literal to each of its negations.k=3G193 Satisfiability Reduces to Independent SetCl

18、aim.G contains independent set of size k=|iff is satisfiable.Pf.Let S be independent set of size k.nS must contain exactly one vertex in each triangle.nSet these literals to true.nTruth assignment is consistent and all clauses are satisfied.Pf Given satisfying assignment,select one true literal from

19、 each triangle.This is an independent set of size k.k=3G20ReviewBasic reduction strategies.nSimple equivalence:INDEPENDENT-SET P VERTEX-COVER.nSpecial case to general case:VERTEX-COVER P SET-COVER.nEncoding with gadgets:3-SAT P INDEPENDENT-SET.Transitivity.If X P Y and Y P Z,then X P Z.Pf idea.Compo

20、se the two algorithms.Ex:3-SAT P INDEPENDENT-SET P VERTEX-COVER P SET-COVER.21Self-ReducibilityDecision problem.Does there exist a vertex cover of size k?Search problem.Find vertex cover of minimum cardinality.Self-reducibility.Search problem P decision version.nApplies to all(NP-complete)problems i

21、n this chapter.nJustifies our focus on decision problems.Ex:to find min cardinality vertex cover.n(Binary)search for cardinality k*of min vertex cover.nFind a vertex v such that G v has a vertex cover of size k*-1.any vertex in any min vertex cover will have this propertynInclude v in the vertex cover.nRecursively find a min vertex cover in G v.

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 教育专区 > 大学资料

本站为文档C TO C交易模式,本站只提供存储空间、用户上传的文档直接被用户下载,本站只是中间服务平台,本站所有文档下载所得的收益归上传人(含作者)所有。本站仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。若文档所含内容侵犯了您的版权或隐私,请立即通知淘文阁网,我们立即给予删除!客服QQ:136780468 微信:18945177775 电话:18904686070

工信部备案号:黑ICP备15003705号© 2020-2023 www.taowenge.com 淘文阁