2024-12-07 21:07:38 +01:00

83 lines
3.8 KiB
Markdown

---
type: theoretical
---
![Video](https://www.youtube.com/watch?v=mdQzAp7gSns)
![Video 2](https://youtu.be/pQsdygaYcE4)
## Definition
- Class P
- The set of decision problems that can be solved by a deterministic Turing machine in polynomial time[^1]. These are problems considered to be efficiently solvable.
- $O(\log n)$
- The set of decision problems for which a given solution can be verified in polynomial time by a deterministic Turing machine[^2]. NP stands for "nondeterministic polynomial time."
- :LiLoaderPinwheel: Does $\mathbf{P = NP}$?
- This is one of the most important open questions in computer science. It asks whether every problem whose solution can be quickly verified can also be quickly solved.
## Understanding P and NP
![](Pasted%20image%2020241203234032.png)
### Class P Problems
- Solvable in polynomial time.
- Algorithms exist that can find a solution efficiently as the input size grows.
- **As seen in**:
- Prime Testing: Determining if a number is prime.
- Shortest Path: Finding the shortest path in a graph (e.g., Dijkstra's algorithm).
- Sorting Algorithms: Such as Quick Sort and Merge Sort.
### Class NP Problems
- Solutions can be verified in polynomial time.
- No known polynomial-time algorithms to solve all NP problems.
- **As in**:
- Subset Sum: Determining if a subset of a given set of integers sums up to a target integer.
- 3-SAT: Determining if a Boolean formula in conjunctive normal form with at most three literals per clause is satisfiable.
- Hamiltonian Cycle: Determining if a Hamiltonian cycle exists in a graph.
## NP-Complete Problems
- The hardest problems in NP. A problem is NP-Complete if:
- It is in NP.
- Every problem in NP can be reduced to it in polynomial time[^3].
- Implications: If any NP-Complete problem is solvable in polynomial time, then $P = NP$.
- Traveling Salesperson Problem (Decision Version): Determining if there's a tour shorter than a given length.
- Clique Problem: Finding a complete subgraph (clique) of a certain size in a graph.
- Vertex Cover: Determining if there exists a set of vertices covering all edges.
## Problems
### Subset Sum Problem
- **Input**: A set of integers and a target sum.
- **Question**: Is there a subset whose sum equals the target?
- **Approach**:
- **Exponential Time**: Checking all possible subsets.
- **Dynamic Programming**: Pseudo-polynomial time algorithm when numbers are small.
### 3-SAT Problem
- **Input**: A Boolean formula in 3-CNF (Conjunctive Normal Form).
- **Question**: Is there a truth assignment that satisfies the formula?
- **Importance**: The first problem proven to be NP-Complete (Cook-Levin theorem).
## Strategies
- Find solutions close to optimal in polynomial time.
- Practical methods that find good-enough solutions without guaranteeing optimality (heuristics).
- Restricting the problem to a subset where it becomes solvable in polynomial time.
## NP vs. NP-Complete Differences
|**Aspect**|**NP**|**NP-Complete**|
|---|---|---|
|**Definition**|Problems whose solutions can be verified quickly.|Hardest problems in NP. All NP problems reduce to them.|
|**Relation to P**|Contains P (P ⊆ NP).|If any NP-complete problem is in P, P = NP.|
|**Ease of Solution**|Some problems may have unknown solution methods.|Believed to be computationally difficult to solve.|
|**Examples**|Subset Sum, 3-SAT|TSP, Clique, Vertex Cover|
![](Pasted%20image%2020241203234600.png)
[^1]: a theoretical computing machine that uses a predetermined set of rules to determine its actions.
[^2]: a theoretical model that, unlike a deterministic Turing machine, can make "guesses" to find solutions more efficiently.
[^3]: a method of converting one problem to another in polynomial time, preserving the problem's computational complexity.
[^4]: the complements of NP-Complete problems, where verifying a "no" instance is in NP.