Unit 6 - Notes
Unit 6: Number-Theoretic Algorithms and Complexity Classes
1. Number Theory Problems
Number theory plays a fundamental role in modern cryptography, hashing algorithms, and randomized algorithms. This section covers the essential number-theoretic tools and algorithms used in computer science.
1.1 Modular Arithmetic
Modular arithmetic is a system of arithmetic for integers, where numbers "wrap around" upon reaching a certain value, called the modulus.
- Definition: If and are integers and is a positive integer, then is congruent to modulo , denoted as , if divides . Equivalently, and have the same remainder when divided by .
- Properties:
- Addition:
- Subtraction:
- Multiplication:
- Exponentiation: is usually computed efficiently using the Modular Exponentiation algorithm (Repeated Squaring), which runs in time.
- Modular Multiplicative Inverse: An integer such that . It exists if and only if (i.e., and are coprime). It can be found using the Extended Euclidean Algorithm.
1.2 Greatest Common Divisor (GCD)
The Greatest Common Divisor of two non-zero integers and is the largest positive integer that divides both and without a remainder.
Euclidean Algorithm
The Euclidean algorithm is an efficient method for computing the GCD. It is based on the principle that the GCD of two numbers does not change if the larger number is replaced by its difference with the smaller number. In practice, modulo is used.
- Theorem:
- Base Case:
Algorithm (Recursive):
def gcd(a, b):
if b == 0:
return a
return gcd(b, a % b)
- Time Complexity: (Lamé's Theorem).
Extended Euclidean Algorithm
This algorithm finds the GCD of and , and also finds the coefficients and (Bézout coefficients) such that:
This is heavily used in finding modular multiplicative inverses.
1.3 Chinese Remainder Theorem (CRT)
The Chinese Remainder Theorem states that if one knows the remainders of the Euclidean division of an integer by several integers, then one can determine uniquely the remainder of the division of by the product of these integers, provided the divisors are pairwise coprime.
-
Statement: Given pairwise coprime positive integers and arbitrary integers , the system of simultaneous congruences:
has a unique solution modulo . -
Construction/Algorithm:
- Compute .
- For each , compute .
- Compute , the modular inverse of modulo (i.e., ).
- The solution is .
-
Applications: Fast computation of large numbers (e.g., in RSA cryptography) by breaking them down into smaller computations.
2. Optimization Problems vs. Decision Problems
Before entering complexity classes, it is crucial to distinguish between problem types.
- Optimization Problem: Asks for the "best" (minimum or maximum) solution among all feasible solutions.
- Example: Traveling Salesperson Problem (TSP) - Find the shortest route visiting all cities.
- Decision Problem: Asks a "Yes/No" question.
- Example: TSP Decision Version - Is there a route visiting all cities with a length ?
- Relationship: Every optimization problem can be mapped to a decision problem. If an optimization problem is easy, the corresponding decision problem is easy. If a decision problem is hard, the corresponding optimization problem is at least as hard. Complexity theory usually focuses on Decision Problems for mathematical standardization.
3. Basic Concepts of Complexity Classes
Computational Complexity Theory classifies problems based on the resources (time and space) required to solve them using an algorithm.
3.1 Class P (Polynomial Time)
- Definition: The class P consists of all decision problems that can be solved by a Deterministic Turing Machine (a standard computer) in polynomial time.
- Meaning: An algorithm exists with a worst-case time complexity of , where is the input size and is a constant.
- Characteristics: These problems are considered mathematically "tractable" or "easy" to solve.
- Examples: Sorting algorithms, finding the shortest path in a graph (Dijkstra's), determining if a number is prime, computing GCD.
3.2 Class NP (Nondeterministic Polynomial Time)
- Definition: The class NP consists of all decision problems for which a given proposed solution ("certificate") can be verified by a Deterministic Turing Machine in polynomial time.
- Alternative Definition: Problems that can be solved by a Non-deterministic Turing Machine in polynomial time. (A non-deterministic machine can "guess" the right answer and verify it instantly).
- Relationship to P: . Any problem that can be solved in polynomial time can certainly have its solution verified in polynomial time.
- Examples:
- Subset Sum: Given a set of integers, is there a non-empty subset whose sum is zero? (Hard to find, but given a subset, easy to verify by adding).
- Graph Coloring: Can a graph be colored with colors such that no adjacent vertices share a color?
3.3 Class NP-Hard
- Definition: A problem is NP-hard if every problem in NP can be reduced to in polynomial time ().
- Meaning: NP-hard problems are at least as hard as the hardest problems in NP. If you could solve an NP-hard problem in polynomial time, you could solve all NP problems in polynomial time.
- Characteristics:
- They do not have to be decision problems (they can be optimization problems).
- They do not have to be in NP (their solutions might not be verifiable in polynomial time).
- Examples: The Halting Problem (undecidable, not in NP), Optimization version of TSP.
3.4 Class NP-Complete
- Definition: A problem is NP-complete if it satisfies two conditions:
- It is in NP (solutions can be verified in polynomial time).
- It is NP-hard (all other NP problems can be polynomially reduced to it).
- Significance: NP-complete problems are the "hardest" problems in NP. They form the core of the P vs. NP debate.
- Polynomial Reduction (): A process of transforming an instance of problem into an instance of problem in polynomial time, such that the answer to is "yes" if and only if the answer to is "yes".
- Cook-Levin Theorem: Proved that the Boolean Satisfiability Problem (SAT) is NP-complete. This was the first problem proven to be NP-complete, providing a baseline to prove others via reduction.
- Classic Examples of NP-Complete Problems:
- SAT (Satisfiability): Given a Boolean formula, is there an assignment of True/False values that makes the formula True?
- 3-SAT: A special case of SAT where each clause has exactly 3 literals.
- Decision TSP: Is there a tour of length ?
- Vertex Cover: Is there a set of vertices that touch every edge in a graph?
- Knapsack Problem (Decision version): Can a value of at least be achieved without exceeding weight ?
3.5 The P vs NP Problem
- The Question: Does ?
- If , it means that if a solution to a problem can be easily checked, the problem can also be easily solved. (This would break modern cryptography).
- If (which is widely believed), it means there are problems whose solutions can be verified quickly, but finding the solution takes an impractically long time (exponential time).
- Proving any single NP-complete problem to have a polynomial-time algorithm would instantly prove .