最近因为要证明np问题,所以找了一系列概念去理解这4个问题。理解的时候看到好多人给出了不同的答案,我下面会借鉴别人的答案来总结出一份对于我自己来说,最容易理解这4个问题的说法。

预备知识了解:

这部分内容的参考链接

时间复杂度

表明问题规模扩大后,程序需要的时间长度增长得有多快。程序的时间复杂度一般可以分为两种级别:

(个人感想:这个对于程序员或者学数学或其他的来说不陌生,从程序的角度出发,就是一个程序运行所需要的时间和输入size存在的一个关于时间上的关系。)

- 多项式级的复杂度,如O(1),O(log(n))、O(n^a)等,- 非多项式级的,如O(a^n)、O(n!)等。后者的复杂度计算机往往不能承受。

约化(Reducibility)

(个人感想:这个理解是我看过那么多概念觉得最能理解的,最简洁的。约化是这4个问题之间相互转换的关键)

简单的说,一个问题A可以约化为问题B的含义是,可以用问题B的解法解决问题A。(个人感觉也就是说,问题A是B的一种特殊情况。)标准化的定义是,如果能找到一个变化法则,对任意一个A程序的输入,都能按照这个法则变换成B程序的输入,使两程序的输出相同,那么我们说,问题A可以约化为问题B。

例如求解一元一次方程这个问题可以约化为求解一元二次方程,即可以令对应项系数不变,二次项的系数为0,将A的问题的输入参数带入到B问题的求解程序去求解。

另外,约化还具有传递性,A可以化约为B,B可以约化为C,那么A也可以约化为C。

多项式时间内找出这个解&多项式时间内验证这个解

(个人感想:这个概念也是很重要的,我觉得对于理解是不可忽视的一个概念)

比如说著名的背包问题Knapsack problem,你要在多项式的时间内找出这个解释很困难的,但是如果有人给了一个解给你,你来验证这个解(看一下每个背包是否可以装得下这个解分配的物品),这个是可以在有效时间内验证的,毕竟对于这个背包问题来说,它的验证十分简单。

p问题、np问题、npc问题、np难问题的概念:

stackoverflow上的回答?

quora上的回答

(个人感想:这个stackoverflow上面最高票的答案的说法是我觉得,没有能够比拟的,还有一个不错的是一个斯坦福的TA在quora上的回答,下面我会粘贴stackoverflow上最高票的这个答案,如果第一遍读了不能理解,那就读第二遍,直到读懂为止。)

P

P is a complexity class that represents the set of all decision problems that can be solved in polynomial time.

That is, given an instance of the problem, the answer yes or no can be decided in polynomial time.

Example

Given a connected graph G, can its vertices be coloured using two colours so that no edge is monochromatic?

Algorithm: start with an arbitrary vertex, color it red and all of its neighbours blue and continue. Stop when you run out of vertices or you are forced to make an edge have both of its endpoints be the same color.


NP

NP is a complexity class that represents the set of all decision problems for which the instances where the answer is "yes" have proofs that can be verified in polynomial time.

This means that if someone gives us an instance of the problem and a certificate (sometimes called a witness) to the answer being yes, we can check that it is correct in polynomial time.

Example

Integer factorisation is in NP. This is the problem that given integers n and m, is there an integer f with 1 < f < m, such that f divides n (f is a small factor of n)?

This is a decision problem because the answers are yes or no. If someone hands us an instance of the problem (so they hand us integers n and m) and an integer f with 1 < f < m, and claim that f is a factor of n (the certificate), we can check the answer in polynomial time by performing the division n / f.


NP-Complete

NP-Complete is a complexity class which represents the set of all problems X in NP for which it is possible to reduce any other NP problem Y to X in polynomial time.

Intuitively this means that we can solve Y quickly if we know how to solve X quickly. Precisely, Yis reducible to X, if there is a polynomial time algorithm f to transform instances y of Y to instances x = f(y) of X in polynomial time, with the property that the answer to y is yes, if and only if the answer to f(y) is yes.

Example

3-SAT. This is the problem wherein we are given a conjunction (ANDs) of 3-clause disjunctions (ORs), statements of the form

(x_v11 OR x_v21 OR x_v31) AND
(x_v12 OR x_v22 OR x_v32) AND
...                       AND
(x_v1n OR x_v2n OR x_v3n)

where each x_vij is a boolean variable or the negation of a variable from a finite predefined list (x_1, x_2, ... x_n).

It can be shown that every NP problem can be reduced to 3-SAT. The proof of this is technical and requires use of the technical definition of NP (based on non-deterministic Turing machines). This is known as Cook's theorem.

What makes NP-complete problems important is that if a deterministic polynomial time algorithm can be found to solve one of them, every NP problem is solvable in polynomial time (one problem to rule them all).


NP-hard

Intuitively, these are the problems that are at least as hard as the NP-complete problems. Note that NP-hard problems do not have to be in NP, and they do not have to be decision problems.

The precise definition here is that a problem X is NP-hard, if there is an NP-complete problem Y, such that Y is reducible to X in polynomial time.

But since any NP-complete problem can be reduced to any other NP-complete problem in polynomial time, all NP-complete problems can be reduced to any NP-hard problem in polynomial time. Then, if there is a solution to one NP-hard problem in polynomial time, there is a solution to all NP problems in polynomial time.

Example

The halting problem is an NP-hard problem. This is the problem that given a program P and input I, will it halt? This is a decision problem but it is not in NP. It is clear that any NP-complete problem can be reduced to this one. As another example, any NP-complete problem is NP-hard.

My favorite NP-complete problem is the Minesweeper problem.


P = NP

This one is the most famous problem in computer science, and one of the most important outstanding questions in the mathematical sciences. In fact, the Clay Institute is offering one million dollars for a solution to the problem (Stephen Cook's writeup on the Clay website is quite good).

It's clear that P is a subset of NP. The open question is whether or not NP problems have deterministic polynomial time solutions. It is largely believed that they do not. Here is an outstanding recent article on the latest (and the importance) of the P = NP problem: The Status of the P versus NP problem.

The best book on the subject is Computers and Intractability by Garey and Johnson.

个人对这4个np问题的小总结:

1. p问题只是np问题的一个子类。

2. 所有的np问题都可以归约为npc问题(这就是为什么说如果能在解决了npc问题,即在多项式时间内找出npc问题的解,就可以得出np=p。因为在多项式时间内找出npc问题的解,那么肯定可以在在多项式时间内找出np问题的解,即np=p)。

3. 所有的npc问题之间都可以相互转换。

4. 所有的npc问题都可以归约为np-hard问题(这就是为什么说如果能在解决了np-hard问题,即在多项式时间内找出np-hard问题的解,就可以得出np=p。因为在多项式时间内找出np-hard问题的解,那么肯定可以在在多项式时间内找出npc问题的解,最后结果就是在在多项式时间内找出np问题的解,即np=p)。

所以实质上np、npc、np-hard只是科学家在为解决np问题上将问题进一步简化,将很多个np问题用一个npc问题去解决,接着将很多个npc问题用一个np-hard问题去解决。但是我还是有点不太理解npc是np和np-hard的交集这个说法,我承认npc是np里面的一个子类,也能理解有的问题是as hard as npc but could not prove it in in polynomial time。但这个交集的说法我时而理解时而不理解,也希望有好心人能给我解答一下。这个交集是指这个问题的难度吗?

经典的npc问题SAT

暂时还没看,大概是关于图灵的转换机,是cook提出并且证实了SAT是第一个npc问题,即可以在polynomial time验证这个解,但这个问题还没有被解决。

经典的np-hard问题:停机问题

我滴妈,我真的看了好久这个啊,最终看了好几个才理解。这个我最终觉得有点像一个问题:到底是有鸡先还是有蛋先

首先大家可以先理解一下经典的理发师问题

预备知识: 理发师悖论

克里克岛的一座小城里有位理发师, 有一天他做出一项规定: 他给并且只给那些不给自己理发的人理发. 理发师的这个规定似乎很有道理, 既然有人自己给自己理发了, 那么我就不用"多此一举", 我再给这个人理发.

最初, 这个规定并没什么问题, 后来, 随着这个理发师自己的头发越来越长, 他发现他陷入了一个两难的境地: 他该不该给自己理发?

  • 如果他为自己理发. 那么他就成为了他规定中那个"自己给自己理发的人", 那么他就不应该为自己理发;
  • 如果他不为自己理发, 那么他不是他规定中那个"自己给自己理发的人", 那么他就应该为自己理发.

综合以上两种情况, "他为自己理发"当且仅当"他不为自己理发", 这成为了一个悖论.

理发师悖论在很多领域有重要的应用, 比如罗素利用理发师悖论发现了集合论的缺陷, 在当时学术界引起了极大震动. 在这里, 我们要用理发师悖论分析停机问题.

停机问题:

(个人感想:用程序来理解是最好的,下面这个代码的解释我是参考知乎上面的一个回答,出处在答案的低端,我觉得这个答案是比较简洁明了的)

1.首先定义一个检测程序

boolean detect(P) //输入参数为函数P 结果返回是否停机 停机true 否则 false

2.定义一个程序,根据detect返回的结果来决定自身是 无限循环 还是 停机

其中 T 为test函数本身

boolean test(T){

if(detect(test(T))){ //检测是否停机

loop() // 无限循环

}else{

return //返回 程序停止

}

}

很显然,当判定程序 detect(test(T)) 检测结果为 true时,即停机的时候,test(T)进入 loop 即无限循环中,此处存在矛盾。反之,当检测结果为false时,即没有停机,test(T) 程序结束,也是有矛盾的。

作者:知乎用户
链接:https://www.zhihu.com/question/20081359/answer/279950224
来源:知乎
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。

有点小意思的文章:

(个人感想:为什么说解决了np-hard这个停机问题,所有的npc问题都能解决了呢?我觉得下面这篇文章也给了大家一个很好的理解方法去理解这4个问题之间。)

文章链接

最后的最后

这个是维基百科的common npc problems,我觉得很有用,大家如果想要证明自己的问题,可以规约为npc

https://en.wikipedia.org/wiki/List_of_NP-complete_problems

p问题、np问题、npc问题、np难问题的理解(纯属个人见解)相关推荐

  1. P、NP、NPC(NP完全问题)、NP-hard问题概述

    P.NP.NPC(NP完全问题).NP-hard问题概述 一.概念总结 1.P问题: 能在多项式时间内解决的问题 2.NP问题: 不能在多项式时间内解决或不确定能不能在多项式时间内解决,但能在多项式时 ...

  2. (数学)P、NP、NPC、NP hard问题

    概念定义: http://m.elecfans.com/article/757041.html https://www.cnblogs.com/AndyJee/p/5048556.html P问题:能 ...

  3. P,NP,NPC(NP完备),NP-hard(NP难),时间复杂度

    P是在多项式时间可以"解决"的一类问题. NP(Non-deterministic Polynomial)是给我们一个解,在多项式时间可以"验证"解是否正确. ...

  4. P、NP以及NPC问题

    P.NP.NPC 概念 > P问题:能够在多项式时间内解决的决策问题. -举例: 图搜索问题.最短路径问题.最小生成树问题······ > NP问题:不能在多项式时间内解决或不确定能不能在 ...

  5. P、NP与NPC 的通俗理解

    P.NP与NPC 的通俗理解 1.多项式时间复杂度 定义: 解决问题需要的时间与问题的规模之间是多项式关系. 多项式关系形如O(nk)" role="presentation&qu ...

  6. p,np,npc,np难问题,确定图灵机与非确定图灵机

    本文转自豆瓣_燃烧的影子 图灵机与可计算性 图灵(1912~1954)出生于英国伦敦,19岁进入剑桥皇家学院研究量子力学和数理逻辑.1935年,图灵写出了"论高斯误差函数"的论文, ...

  7. NP问题、NP难问题(NPH)和NP完全问题(NPC)理解

    看算法的时候经常会碰到NP问题.NP难问题(NPH)和NP完全问题(NPC)等术语,每次碰到的时候都似懂非懂,这次专门在网上搜了一些资料看,做一下记录,权当加深印象. NP是指Non-determin ...

  8. 【计算理论】计算理论总结 ( P 、NP 、NPC 总结 ) ★★

    文章目录 一.P 类 二.NP 类 三.NPC 类 ( NP 完全 ) 四.P .NP .NPC 三者关系 一.P 类 P\rm PP 类 : ★ 所有 能够被 确定性 单个带子图灵机 , 在 多项式 ...

  9. P、NP、NPC问题

    转自:http://blog.csdn.net/wwy851/article/details/6082007 最近看了很多关于P.NP和NPC问题的文章,但是都不是很系统全面,很多叙述的也不太清楚,有 ...

最新文章

  1. 安装 sklearn 报错 ImportError: cannot import name Type
  2. NYOJ 585 取石子(六)
  3. apache URL重写
  4. XCode7 创建framework
  5. php 避免xss_PHP防止XSS注入
  6. java各种排序实现
  7. arch linux u盘安装,安装 ArchLinux 到U盘(四)安装Archlinux
  8. CodeSmith 第一次用,遇到问题了
  9. PDF区域文本提取工具
  10. 共轭梯度法(Conjugate Gradients)(1)
  11. iOS录音、播放、WAV以及caf转成MP3上传后台
  12. oracle10非正常删除卸载干净,win10系统下把Oracle卸载干净
  13. 2014汽车之家笔试
  14. C语言实现扫雷游戏完整代码
  15. 扫描全能王完美版,纸质文件一键识别电子文档
  16. Nanopore 纳米孔 测序数据处理 微生物 16S全长 Centrifuge的安装和使用
  17. 《RHCE考试必看》
  18. 算法逻辑题-海盗分金币问题
  19. 基于单目和低成本GPS的车道定位方法
  20. 中鑫吉鼎|不同人生阶段的女性理财方式

热门文章

  1. TextRank算法介绍及实现
  2. 网站被攻击了要怎么处理
  3. 程序员家的孩子休学是怎么书写休学申请书的
  4. 微信小程序开发教程5:设置全局css样式
  5. VS恢复默认设置方法
  6. 【博学谷学习记录】超强总结,用心分享 _ 前端开发 vue3
  7. arduino实现简易计算器
  8. 小姑子一家三口未经同意来我家过年,我很生气,各位朋友怎么看?
  9. ubuntu虚拟机磁盘扩容
  10. 敏捷开晨会不是汇报工作