Open In App

P vs NP Problems

Last Updated : 11 Jan, 2024
Improve
Improve
Like Article
Like
Save
Share
Report

In the world of computers and math, there’s this puzzling question: Can every problem we quickly check be solved quickly too? We have two categories: P for problems with quick solutions, and NP for problems where checking is fast, but solving might not be. This article explores these P vs NP problems, trying to understand why some things are easy to check but hard to figure out, and why it matters for how computers work.

What is P problems?

Polynomial time problems, commonly known as P problems. The solution of the problem can be found in polynomial time.

Example: Linear search, whose time complexity is O(N), where N is the input size.

Key characteristics of P problems:

Characteristic Description
Definition Problems in the P complexity class are decision problems that can be efficiently solved by a deterministic Turing machine in polynomial time.
Time Complexity Solutions can be found in polynomial time, meaning the time required for computation grows at most as a polynomial function of the input size.
Algorithmic Solutions Efficient algorithms exist for solving P problems, making them computationally tractable and practical for a wide range of applications.
Polynomial Verification The correctness of a solution can be verified in polynomial time, ensuring that the proposed solution is correct without significant computational effort.
Examples Examples of P problems include sorting algorithms, searching algorithms, and various problems with known efficient solutions.

What is NP problems?

Nondeterministic polynomial-time problems, commonly known as NP problems. These problems have the special property that, once a potential solution is provided, its correctness can be verified quickly. However, finding the solution itself may be computationally difficult.

Example: A well-known example of NP problems is prime factorization. We can verify a factor of an integer in polynomial time. However, we don’t know any polynomial time algorithm to factorize a given integer.

Key characteristics of NP problems:

Characteristic Description
Definition Nondeterministic Polynomial time problems are computational problems for which solutions can be verified efficiently in polynomial time.
Verification Once a potential solution is provided, its correctness can be verified quickly using a nondeterministic algorithm in polynomial time.
Solution Computation While verification is efficient, finding a solution may be computationally challenging, with no known polynomial time algorithm for general instances.
Example The Traveling Salesman Problem (TSP) is a classic NP problem.

Difference between P vs NP problems:

Here’s a detailed explanation of the differences between P and NP problems:

Feature P Problems NP Problems
Solvability Efficiently solvable in polynomial time. Efficient verification, solution may not be found efficiently.
Time Complexity Polynomial time algorithms are known. Efficient verification algorithms are known, but efficient solution algorithms are not guaranteed.
Nature of Solutions Solutions can be found efficiently. Solutions, once proposed, can be verified efficiently.
Decision or Optimization Often decision problems (yes/no answers). Can be decision or optimization problems.
Known Relationship P is a subset of NP. It is unknown whether NP is a proper subset of P or if they are equal.
Practical Implications Problems in P are considered efficiently solvable in practice. NP problems are considered computationally hard; no efficient algorithm is currently known, making them potentially impractical for large instances.
P vs NP Question P vs NP question is open. One of the most significant open problems in computer science is whether P equals NP. If P equals NP, all problems in NP would also be in P.
Example Sorting, searching, shortest path problems. Traveling Salesman, Boolean Satisfiability.

Related Articles:



Similar Reads

Practice Problems on Hashing
In this article, we will discuss the types of questions based on hashing. Before understanding this, you should have idea about hashing, hash function, open addressing and chaining techniques (see: Introduction, Separate chaining, Open addressing). These are some key points in hashing: The purpose of hashing is to achieve search, insert and delete
8 min read
Top 50 Problems on Heap Data Structure asked in SDE Interviews
A Heap is a special Tree-based Data Structure in which the tree is a complete binary tree. Generally, heaps are of two types: Max-Heap and Min-Heap. To know more about this Data Structure in-depth refer to the Tutorial on Heap Data-Structure. Given below are the most frequently asked interview questions on Heaps:  Easy Interview Questions on Heap D
2 min read
Problems not solved at the end of Nth day
Given 3 integers K, P and N. Where, K is the number of problems given to the person every day and P is the maximum number of problems he can solve in a day. Find the total number of problems not solved after the N-th day.Examples: Input : K = 2, P = 1, N = 3 Output : 3 On each day 1 problem is left so 3*1 = 3 problems left after Nth day. Input : K
4 min read
Some Tricks to solve problems on Impartial games
How to solve problems that fall in the Finders keepers category in 'Game Theory'? Note- Finders keepers game fall into the category of 'Impartial Games' in 'Game Theory'. What are 'Impartial Games'? Let a game is being played between two players 'A' and 'B'. A game between them is said to be 'Impartial' if both the players have same set of moves. W
4 min read
How to solve problems related to Number-Digits using Recursion?
The process in which a function calls itself directly or indirectly is called recursion and the corresponding function is called a recursive function. Using a recursive algorithm, certain problems can be solved quite easily. A method to solve the number digit problems using recursion is discussed in this article. Two main components exist for any r
4 min read
Miscellaneous Problems of Time Complexity
Prerequisite : Asymptotic Notations Time Complexity :Time complexity is the time needed by an algorithm expressed as a function of the size of a problem. It can also be defined as the amount of computer time it needs to run a program to completion. When we solve a problem of time complexity then this definition help the most - "It is the number of
16 min read
What are Ad Hoc Problems in Competitive Programming?
The Ad Hoc problems are problems that cannot be classified anywhere else in the categories with well-studied solutions since each problem description and its corresponding solution are unique. These problems don't fall under standard categories, there is no specific or general technique exists to solve them. Many Ad Hoc problems are easy, but this
5 min read
Crossword Puzzle Of The Week #33(Chessboard Problems)
In this issue of Crossword Puzzle of the Week, we will dive into the topic of Chessboard Problems. The solution to the crossword puzzle is provided at the end. [caption width="800"]Crossword #33[/caption]HINTS: Across: 1. ________happens when king is in a position where it is under attack and cannot escape capture on the next move.5. A standard che
1 min read
Detection of possible / potential stack overflow problems in a c / c++ program
Stack overflow is a common problem in computer programming and can lead to unpredictable behavior and security vulnerabilities in C / C++ programs. It is important for developers to be able to identify and address potential stack overflow problems so they can be avoided or fixed before they cause any issues. In this blog post, we'll go over some of
4 min read
Top 50 Problems on Queue Data Structure asked in SDE Interviews
A Queue is defined as a linear data structure that is open at both ends and the operations are performed in First In First Out (FIFO) order. We define a queue to be a list in which all additions to the list are made at one end, and all deletions from the list are made at the other end. The element which is first pushed into the order, the operation
3 min read