1.0 - Polynomial Time Algorithms - Tractable
- Polynomial-time problems are considered tractable (i.e., feasible to solve)
- in practice, an algorithm of complexity is not tractable
- However, if a problem has a polynomial time algorithm, there is usually an efficient polynomial-time algorithm.
1.1 - Polynomial Time Algorithms - Computational Models
- The class of problems solvable in polynomial time on a serial random-access machine (as we have been using) is the same as:
- The class problems that can be solve in polynomial time on an abstract Turing machine;
- The class of problems that can be solved in polynomial-time on a parallel compute where the number of processors grows polynomially with input size.
- For many reasonable models the class of problems that can be solved in polynomial time is the same.
1.2 - Examples of Polynomial and Non-Polynomial Algorithms
1.2.1 - Polynomial Time - Closure Properties
-
Polynomials are closed under addition, multiplication and composition
- Addition: Run one polynomial time algorithm, then run a second one.
- Multiplication: Run a polynomial time algorithm a polynomial number of times
- Composition: Run a polynomial time algorithm on the output of another polynomial-time algorithm (or run an poly-time algorithm on an input of polynomial size).
-
For example, if the output of a polynomial time algorithm is fed as input to another polynomial time algorithm , the composite algorithm is polynomial time
-
Note that the size of the input of may be polynomial in the size of its input
-
Which problem have polynomial-time algorithms? Problems that seem similar may not have the same time complexity.
-
We can find the shortest paths from a single source vertex in a directed graph in time
-
Finding a longest simple path between two vertices is difficult.
- Simple path - a path with no repeated edges or vertices
-
Even determining whether a graph contains a simple path with at least a given number of vertices is hard (it is NP-complete)
1.2.2 - Euler Tour vs Hamiltonian Cycle
- An Euler tour in a connected directed graph is cycle in which each edge of the graph is traversed exactly once.
- Finding an Euler tour can be solved in time
- A Hamiltonian cycle in a graph is a simple cycle that contains all the vertices in the graph.
- Though one is a traversal of vertices (Euler), and once is traversal of edges (Hamiltonian), one is completed in linear time, and the other is exponential-time.
- Determining whether a graph has a Hamiltonian cycle is difficult (it is NP-complete)
1.2.3 - 2-CNF vs 3-CNF satisfiability
-
A Boolean formula, such as
has a satisfying assignment such that it evaluates to 1.
-
A Boolean formula is in conjunctive normal form (CNF) if it is a conjunction of clauses, each of which is a disjunction of literals, each of which is either a variable or its negation
- Putting expressions into normal forms can help us to complete proofs - we take many problem instances and put them into a common format.
-
It is in form if it is in CNF form in which each disjunction has exactly literals - the example above is in .
-
Determining whether a formula is satisfiable can be done in polynomial time
-
Determining whether a formula is satisfiable is difficult (it is NP-complete)
1.3 - Defining Classes of Problems
- Which problems have polynomial-time algorithms?
- To study this, in complexity theory we study classes of problems (not algorithms)
- We focus on decision problems rather than optimisation problems
- We focus on concrete problems rather than abstract problems
1.3.1 - Decision Problems
- Decision problems have a simple 1 or 0 answer as their solution
- Optimisation problems usually have closely related decision problems
- If the optimisation problem is “easy”, the related decision problem is also “easy”
- If the optimisation problem is “hard”, the related decision problem is also “hard”
1.3.2 - Decision Problems: An Example
-
Finding a shortest path in a graph is an optimisation problem
-
Deciding if a graph has a path from u to v with at most is a related decision problem
solve-path(G, u, v, k) p = solve-shortest-path(G, u, v) if length(p) <= k return 1 else return 0 -
solve-shortest-path can be solved in polynomial time, and hence solve-path can be solved in polynomial time.
-
In this example solve-shortest-path is our optimisation problem, and solve-path uses solve-shortest-path.
-
solve-path is the decision problem.
-
If we cannot solve solve-path in polynomial time then we can argue that we can’t solve solve-shortest-path in polynomial time
2.0 - Complexity Class P
💡 This slide was from Lecture 11.1
- Set of concrete decision problems that are polynomial-time solvable.
- Decision problems have a simple yes or no, answer
- A concrete problem is a problem whose instance set is the set of binary strings
- A concrete problem is polynomial-time solvable if there exists and algorithm to solve it in time for some constant , where is the length of the binary input string
2.1 - Abstract Problems
- An abstract problem is a binary relation on a set of the problem instances and a set of problem solutions
- There may be multiple solutions for a given problem instance - this is why it is a binary relation, not a function
- The problem instance (input to the problem) is not constrained to be any format - it could be a graph, list, etc.
- An abstract decision problem is a function from an instance set to the solution set
- Unique or solution for any given instance
- That is, definitively a yes or no answer.
2.2 - Encodings
- We need to represent problem instances in a way that a program can understand
- An encoding of a set of abstract projects is a mapping from to the set of binary strings
- Encode a natural number in the usual way:
- Encode a compound object as a binary string combining the representations of the constituent parts.
2.3 - Concrete Problems
- A concrete problem is a problem whose instance set is the set of binary strings
- The input format is now constrained to binary inputs
- An algorithm solves a concrete problem in time if when it is provided a problem instance of length , the algorithm produces a solution in time.
- Measuring running time as a function of the number of bits in the input
2.4 - Complexity Class P
- A concrete problem is polynomial-time solvable if there exists an algorithm to solve it in time for some constant
- The complexity class is the set of concrete decision problems that are polynomial-time solvable
3.0 - Encoding Abstract Problems as Concrete Problems
-
A abstract decision problem Q maps a problem instance to .
-
Using an encoding to map an abstract problem to a concrete problem
-
For any instance of the abstract problem , the solution to the concrete problem for is
- That is, we can give the concrete problem the argument which is the encoded abstract input
-
Some binary strings may not correspond to instances in , we assume that such strings arbitrarily map to 0.
3.1 - Polynomial-Time Solvability to Abstract Problems
- Polynomial-time solvability is defined above for concrete problems
- We want to extend the definition to abstract problems using encodings
- But want the definition to be independent of a particular encoding
- Unfortunately, the complexity does depend on the encoding.
3.1.1 - Dependency on Encoding - Example
- Suppose an integer is the sole input to an algorithm
- The algorithm has a running time which is
- If we use a binary representation of
- The size of the input
- The complexity is
- If we use a unary representation of
- is represented by a string of 1s.
- For example, 4 is represented as 1111
- The size of the input is
- The complexity is
- We want to rule out expensive encodings such as the unary encoding.
3.1.2 - Standard Encoding
- We assume a standard encoding in which
- The encoding of an integer is polynomially related to its binary encoding
- The encoding of a finite set is polynomially related to its encoding as a list of its elements enclosed in braces separated by commas (e.g., as in ASCII)
- Use to stand for the standard encoding of
3.2 - Polynomially Related Encodings
-
A function is polynomial-time computable if there exists a polynomial time algorithm , that given any input produces output
-
For a set of problem instances, , two encodings are polynomially related if there exists polynomial timefunctions and such that for any (these functions translate between encodings)
-
And non-instances are mapped to non-instances by both
3.2.1 - Independence from Encoding
- Based on the above results, yields the following lemma
- Given an abstract problem on an instance set , if and are polynomially-related encodings of , then the concrete problem if and only if
- The first encoding of the abstract problem is in complexity class if and only if the second encoding of the abstract problem (given that the first and second encodings are polynomially related)
3.2.2 - Proof
By symmetry, we can show that
-
If then there exists polynomial-time algorithm that solves
-
As and are polynomially-related encodings, then there exists a polynomial-time computable function such that for some problem instance
-
Hence, assume that is some polynomial time algorithm implementing
-
Then the following algorithm implements for instance assuming
A2(i2) i1 = F21(i2) return A1(i1)
- We need to show that is polynomial time
********************Proof that is polynomial-time
- The running time of is for some constant
- The size of is bounded by the running time of and hence
- The running time of is for some constant
- Hence the running time of is
- The running time of is and hence is polynomial as are constants.