Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

can some sorting be P, NP, and NP-Complete?

I am quite confused, and this is my thought after some reading:

P is in NP and NP is in NP-Complete. Therefore, all P could be in NP and NP-Complete?

Does that mean there are sorting algorithms that could be NP and NP-Complete?

Hope this doesn't sound too stupid.

like image 576
Chaos Avatar asked Dec 21 '22 12:12

Chaos


2 Answers

First things first :

P is in NP; NP is in NP-Complete. therefore, all P could be in NP and NP-Complete?

Is quite a statement because what you are saying implies P=NP . No one has been able to prove this or otherwise. So here is the state of affairs :

enter image description here

Most of the people believe that P!=NP. Quoting from Wikipedia :

In a 2002 poll of 100 researchers, 61 believed the answer to be no, 9 believed the answer is yes, and 22 were unsure; 8 believed the question may be independent of the currently accepted axioms and therefore is impossible to prove or disprove.

A simple way to understand is this : Suppose you are given a solution to some problem. If you can verify that whether the solution is correct or not in polynomial time, then the problem is NP. Clearly, every problem that can be solved in polynomial time (P) is in NP (you can solve the problem yourself and compare to the right answer in P time).

Right now we have several problems that can be verified in polynomial time but cannot be solved in the same. We are not sure that whether there can never be a polynomial time solution or are we not able to figure it out just yet.


Sorting Numbers

  • Given a list of numbers, you can verify that whether the list is sorted or not in polynomial time, so the problem is clearly NP.

  • There are known algorithms to sort a list of numbers in polynomial time. (Bubble sort O(n^2) etc. ). Thus the problem is P.

Hope this helps.

Consider giving this blog a read.

like image 87
axiom Avatar answered Jan 09 '23 18:01

axiom


P, NP, NP-hard and NP-complete are complexity classes of problems; they characterize a problem, not an algorithm.

like image 31
COME FROM Avatar answered Jan 09 '23 18:01

COME FROM