01_intro_complexity
01_intro_complexity
Algorithmic Complexity
Introduction
2023
Infos sur l’UE
1
Algorithmic Complexity
Measure the hardness of a problem w.r.t. the efficiency of algorithms
to solve it
I Time
I Space
Complexity Theory
I Classification of problems w.r.t. the resources required to solve
them
I The more we need time and/or space, the harder it is
I Comparison of problems (depending on the class they belong)
I Solving problems by translating them into other problems (with
the same complexity)
Graph Theory
Non-Directed Graphs
Directed Graphs
Logic
Integer mappings
We use mappings f : N → N to represent the time (or space) used to
solve a problem
I Intuition: If the problem entry has size n, f (n) steps are required
to compute the result
I If needed, we use the closest integer value (e.g. log(n) means
dlog(n)e)
Integer mappings
We use mappings f : N → N to represent the time (or space) used to
solve a problem
I Intuition: If the problem entry has size n, f (n) steps are required
to compute the result
I If needed, we use the closest integer value (e.g. log(n) means
dlog(n)e)
∀n ≥ n0 , g(n) ≤ c × f (n)
g(n)
I We suppose that we
have an algorithm
which solves a graphs
problem in
g(n) = 4×n2 +3×n+2
steps, when n is the
size of the graph (i.e.
number of vertices)
n
J.-G. Mailly | Intro to Complexity
Example
6
g(n) 5 × f (n)
I We suppose that we
have an algorithm
which solves a graphs
problem in
g(n) = 4×n2 +3×n+2
steps, when n is the
size of the graph (i.e.
number of vertices)
I When n becomes large
enough, g(n) ≤
5 × f (n) = 5 × n2 , so
g(n) ∈ O(n2 )
n
J.-G. Mailly | Intro to Complexity
Example
6
g(n) 5 × f (n)
I We suppose that we
have an algorithm
which solves a graphs
problem in
g(n) = 4×n2 +3×n+2
steps, when n is the
size of the graph (i.e.
number of vertices)
I When n becomes large
enough, g(n) ≤
5 × f (n) = 5 × n2 , so
g(n) ∈ O(n2 )
n0 n
J.-G. Mailly | Intro to Complexity
On Usual O Families
7
Fast
O(1)
Fast
Slower
O(1)
O(log(n))
Fast
Slower
O(1) •••
O(log(n))
Slower
O(log(n))
O(n!)
Graph Theory
Non-Directed Graphs
Directed Graphs
Logic
Solving an Equation
Decision Problem Does the equation f (x) = y have a solution?
Function Problem Give a solution of the equation f (x) = y
Solving an Equation
Enumeration Problem Give all the solutions of the equation f (x) = y
Optimization Problem Give a minimal solution of the equation
f (x) = y
Definition
I Set of symbols Σ called vocabulary or alphabet.
I A word w is a sequence of symbols w1 w2 . . . wk , with wi ∈ Σ for
all i.
I Σ∗ = {w1 w2 . . . wk | wi ∈ Σ, k ∈ N}
I a language L is any subset of Σ∗ , the complement of L is
L̄ = Σ∗ \ L
Graph Theory
Non-Directed Graphs
Directed Graphs
Logic
Definition
A non-directed graph is a pair G = hN, Ei where N is the set of nodes
and E ⊆ pairs(N) is the set of edges, with
pairs(N) = {{xi , xj } | xi , xj ∈ N}
Definition
A non-directed graph is a pair G = hN, Ei where N is the set of nodes
and E ⊆ pairs(N) is the set of edges, with
pairs(N) = {{xi , xj } | xi , xj ∈ N}
x6
x1 x2 x3 x4 x5
x7
Definition
A subgraph in a non-directed graph G = hN, Ei is a pair
G0 = hN 0 , E 0 i, with N 0 ⊆ N and E 0 ⊆ pairs(N 0 ) ∩ E. If
E 0 = pairs(N 0 ) ∩ E, we say that G0 is the subgraph of G induced by N 0
Definition
A subgraph in a non-directed graph G = hN, Ei is a pair
G0 = hN 0 , E 0 i, with N 0 ⊆ N and E 0 ⊆ pairs(N 0 ) ∩ E. If
E 0 = pairs(N 0 ) ∩ E, we say that G0 is the subgraph of G induced by N 0
x6
⇒ x1 x2 x3
x1 x2 x3 x4 x5
x7
Definition
A subgraph in a non-directed graph G = hN, Ei is a pair
G0 = hN 0 , E 0 i, with N 0 ⊆ N and E 0 ⊆ pairs(N 0 ) ∩ E. If
E 0 = pairs(N 0 ) ∩ E, we say that G0 is the subgraph of G induced by N 0
x6
⇒ x1 x2 x3
x1 x2 x3 x4 x5
x7
Definition
A subgraph in a non-directed graph G = hN, Ei is a pair
G0 = hN 0 , E 0 i, with N 0 ⊆ N and E 0 ⊆ pairs(N 0 ) ∩ E. If
E 0 = pairs(N 0 ) ∩ E, we say that G0 is the subgraph of G induced by N 0
x6
⇒ x1 x2 x3
x1 x2 x3 x4 x5
x7
Definition
A subgraph in a non-directed graph G = hN, Ei is a pair
G0 = hN 0 , E 0 i, with N 0 ⊆ N and E 0 ⊆ pairs(N 0 ) ∩ E. If
E 0 = pairs(N 0 ) ∩ E, we say that G0 is the subgraph of G induced by N 0
x6
⇒ x1 x2 x3
x1 x2 x3 x4 x5
x7
Definition
A chain in a non-directed graph G = hN, Ei is a vector of nodes
(n1 , . . . , nk ) such that ∀0 ≤ i < k , {ni , ni+1 } ∈ E.
Definition
A chain in a non-directed graph G = hN, Ei is a vector of nodes
(n1 , . . . , nk ) such that ∀0 ≤ i < k , {ni , ni+1 } ∈ E.
x6
x1 x2 x3 x4 x5
x7
Definition
A chain in a non-directed graph G = hN, Ei is a vector of nodes
(n1 , . . . , nk ) such that ∀0 ≤ i < k , {ni , ni+1 } ∈ E.
x6
x1 x2 x3 x4 x5
x7
Definition
A chain in a non-directed graph G = hN, Ei is a vector of nodes
(n1 , . . . , nk ) such that ∀0 ≤ i < k , {ni , ni+1 } ∈ E.
x6
x1 x2 x3 x4 x5
x7
Definition
A chain in a non-directed graph G = hN, Ei is a vector of nodes
(n1 , . . . , nk ) such that ∀0 ≤ i < k , {ni , ni+1 } ∈ E.
x6
x1 x2 x3 x4 x5
x7
Definition
A chain in a non-directed graph G = hN, Ei is a vector of nodes
(n1 , . . . , nk ) such that ∀0 ≤ i < k , {ni , ni+1 } ∈ E.
x6
x1 x2 x3 x4 x5
x7
Definition
A clique in a non-directed graph G = hN, Ei is subgraph
G0 = hN 0 , E 0 i, with N 0 ⊆ N and E 0 ⊆ pairs(N 0 ) ∩ E, such that
∀xi , xj ∈ N 0 , xi 6= xj , {xi , xj } ∈ E 0
Definition
A clique in a non-directed graph G = hN, Ei is subgraph
G0 = hN 0 , E 0 i, with N 0 ⊆ N and E 0 ⊆ pairs(N 0 ) ∩ E, such that
∀xi , xj ∈ N 0 , xi 6= xj , {xi , xj } ∈ E 0
x6
x1 x2 x3 x4 x5
x7
Definition
A clique in a non-directed graph G = hN, Ei is subgraph
G0 = hN 0 , E 0 i, with N 0 ⊆ N and E 0 ⊆ pairs(N 0 ) ∩ E, such that
∀xi , xj ∈ N 0 , xi 6= xj , {xi , xj } ∈ E 0
x6
x1 x2 x3 x4 x5
x7
Definition
A cycle in a non-directed graph G = hN, Ei is a chain (n1 , . . . , nk )
such that n1 = nk . The length of the cycle is k − 1
Definition
A cycle in a non-directed graph G = hN, Ei is a chain (n1 , . . . , nk )
such that n1 = nk . The length of the cycle is k − 1
x6
x1 x2 x3 x4 x5
x7
Definition
A cycle in a non-directed graph G = hN, Ei is a chain (n1 , . . . , nk )
such that n1 = nk . The length of the cycle is k − 1
x6
x1 x2 x3 x4 x5
x7
Definition
A directed graph is a pair G = hN, Ei where N is the set of nodes and
E ⊆ N × N is the set of edges
Definition
A directed graph is a pair G = hN, Ei where N is the set of nodes and
E ⊆ N × N is the set of edges
x6
x1 x2 x3 x4 x5
x7
Definition
A subgraph in a directed graph G = hN, Ei is a pair G0 = hN 0 , E 0 i,
with N 0 ⊆ N and E 0 ⊆ (N 0 × N 0 ) ∩ E. If E 0 = (N 0 × N 0 ) ∩ E, we say
that G0 is the subgraph of G induced by N 0
Definition
A subgraph in a directed graph G = hN, Ei is a pair G0 = hN 0 , E 0 i,
with N 0 ⊆ N and E 0 ⊆ (N 0 × N 0 ) ∩ E. If E 0 = (N 0 × N 0 ) ∩ E, we say
that G0 is the subgraph of G induced by N 0
x6
⇒ x1 x2 x3
x1 x2 x3 x4 x5
x7
Definition
A subgraph in a directed graph G = hN, Ei is a pair G0 = hN 0 , E 0 i,
with N 0 ⊆ N and E 0 ⊆ (N 0 × N 0 ) ∩ E. If E 0 = (N 0 × N 0 ) ∩ E, we say
that G0 is the subgraph of G induced by N 0
x6
⇒ x1 x2 x3
x1 x2 x3 x4 x5
x7
Definition
A subgraph in a directed graph G = hN, Ei is a pair G0 = hN 0 , E 0 i,
with N 0 ⊆ N and E 0 ⊆ (N 0 × N 0 ) ∩ E. If E 0 = (N 0 × N 0 ) ∩ E, we say
that G0 is the subgraph of G induced by N 0
x6
⇒ x1 x2 x3
x1 x2 x3 x4 x5
x7
Definition
A subgraph in a directed graph G = hN, Ei is a pair G0 = hN 0 , E 0 i,
with N 0 ⊆ N and E 0 ⊆ (N 0 × N 0 ) ∩ E. If E 0 = (N 0 × N 0 ) ∩ E, we say
that G0 is the subgraph of G induced by N 0
x6
⇒ x1 x2 x3
x1 x2 x3 x4 x5
x7
Definition
A path in a directed graph G = hN, Ei is a vector of nodes (n1 , . . . , nk )
such that ∀0 ≤ i < k , (ni , ni+1 ) ∈ E.
Definition
A path in a directed graph G = hN, Ei is a vector of nodes (n1 , . . . , nk )
such that ∀0 ≤ i < k , (ni , ni+1 ) ∈ E.
x6
x1 x2 x3 x4 x5
x7
Definition
A path in a directed graph G = hN, Ei is a vector of nodes (n1 , . . . , nk )
such that ∀0 ≤ i < k , (ni , ni+1 ) ∈ E.
x6
x1 x2 x3 x4 x5
x7
Definition
A path in a directed graph G = hN, Ei is a vector of nodes (n1 , . . . , nk )
such that ∀0 ≤ i < k , (ni , ni+1 ) ∈ E.
x6
x1 x2 x3 x4 x5
x7
Definition
A path in a directed graph G = hN, Ei is a vector of nodes (n1 , . . . , nk )
such that ∀0 ≤ i < k , (ni , ni+1 ) ∈ E.
x6
x1 x2 x3 x4 x5
x7
Definition
A path in a directed graph G = hN, Ei is a vector of nodes (n1 , . . . , nk )
such that ∀0 ≤ i < k , (ni , ni+1 ) ∈ E.
x6
x1 x2 x3 x4 x5
x7
Definition
A clique in a directed graph G = hN, Ei is subgraph G0 = hN 0 , E 0 i,
with N 0 ⊆ N and E 0 ⊆ (N 0 × N 0 ) ∩ E, such that ∀xi , xj ∈ N 0 , xi 6= xj ,
(xi , xj ) ∈ E 0
Definition
A clique in a directed graph G = hN, Ei is subgraph G0 = hN 0 , E 0 i,
with N 0 ⊆ N and E 0 ⊆ (N 0 × N 0 ) ∩ E, such that ∀xi , xj ∈ N 0 , xi 6= xj ,
(xi , xj ) ∈ E 0
x6
x1 x2 x3 x4 x5
x7
Definition
A clique in a directed graph G = hN, Ei is subgraph G0 = hN 0 , E 0 i,
with N 0 ⊆ N and E 0 ⊆ (N 0 × N 0 ) ∩ E, such that ∀xi , xj ∈ N 0 , xi 6= xj ,
(xi , xj ) ∈ E 0
x6
x1 x2 x3 x4 x5
x7
Definition
A clique in a directed graph G = hN, Ei is subgraph G0 = hN 0 , E 0 i,
with N 0 ⊆ N and E 0 ⊆ (N 0 × N 0 ) ∩ E, such that ∀xi , xj ∈ N 0 , xi 6= xj ,
(xi , xj ) ∈ E 0
x6
x1 x2 x3 x4 x5
x7
Definition
A clique in a directed graph G = hN, Ei is subgraph G0 = hN 0 , E 0 i,
with N 0 ⊆ N and E 0 ⊆ (N 0 × N 0 ) ∩ E, such that ∀xi , xj ∈ N 0 , xi 6= xj ,
(xi , xj ) ∈ E 0
x6
x1 x2 x3 x4 x5
x7
Definition
A cycle in a directed graph G = hN, Ei is a path (n1 , . . . , nk ) such that
n1 = nk . The length of the cycle is k − 1
Definition
A cycle in a directed graph G = hN, Ei is a path (n1 , . . . , nk ) such that
n1 = nk . The length of the cycle is k − 1
x6
x1 x2 x3 x4 x5
x7
Definition
A cycle in a directed graph G = hN, Ei is a path (n1 , . . . , nk ) such that
n1 = nk . The length of the cycle is k − 1
x6
x1 x2 x3 x4 x5
x7
Definition
A cycle in a directed graph G = hN, Ei is a path (n1 , . . . , nk ) such that
n1 = nk . The length of the cycle is k − 1
x6
x1 x2 x3 x4 x5
x7
Definition
A cycle in a directed graph G = hN, Ei is a path (n1 , . . . , nk ) such that
n1 = nk . The length of the cycle is k − 1
x6
x1 x2 x3 x4 x5
x7
Definition
A cycle in a directed graph G = hN, Ei is a path (n1 , . . . , nk ) such that
n1 = nk . The length of the cycle is k − 1
x6
x1 x2 x3 x4 x5
x7
Graph Theory
Non-Directed Graphs
Directed Graphs
Logic
Definition
Propositional logic is a mathematical formalism which studies
propositions, i.e. logical objects which can be true or false. A
propositional formula is the combinations of propositions with
connectives
Definition
Propositional logic is a mathematical formalism which studies
propositions, i.e. logical objects which can be true or false. A
propositional formula is the combinations of propositions with
connectives
Examples of propositions:
I it’s raining
I it’s sunny
I I need an umbrella
I I need sunscreen
Definition
Propositional logic is a mathematical formalism which studies
propositions, i.e. logical objects which can be true or false. A
propositional formula is the combinations of propositions with
connectives
Examples of propositions:
I it’s raining
I it’s sunny
I I need an umbrella
I I need sunscreen
Propositions are usually represented by Boolean variables, i.e.
mathematical objects which can be assigned a value from a binary
set B = {0, 1} (sometimes written {False, True} or {⊥, >})
Intuitively:
I the negation takes the opposite of the original value
Intuitively:
I the negation takes the opposite of the original value
Intuitively:
I the negation takes the opposite of the original value
Intuitively:
I the negation takes the opposite of the original value
I the conjunction is true iff both values are true
Intuitively:
I the negation takes the opposite of the original value
I the conjunction is true iff both values are true
Sets of Atoms
I An interpretation can be written as the set of atoms which are
assigned 1
Sets of Atoms
I An interpretation can be written as the set of atoms which are
assigned 1
I Example: V = {x1 , x2 , x3 }, ω(x1 ) = 0, ω(x2 ) = ω(x3 ) = 1 is
equivalent to ω = {x2 , x3 }
Sets of Atoms
I An interpretation can be written as the set of atoms which are
assigned 1
I Example: V = {x1 , x2 , x3 }, ω(x1 ) = 0, ω(x2 ) = ω(x3 ) = 1 is
equivalent to ω = {x2 , x3 }
Vectors of Bits
I An interpretation can be written as a vector of 0 and 1; the order
has to be fixed (usually lexicographical order)
Sets of Atoms
I An interpretation can be written as the set of atoms which are
assigned 1
I Example: V = {x1 , x2 , x3 }, ω(x1 ) = 0, ω(x2 ) = ω(x3 ) = 1 is
equivalent to ω = {x2 , x3 }
Vectors of Bits
I An interpretation can be written as a vector of 0 and 1; the order
has to be fixed (usually lexicographical order)
I Example: V = {x1 , x2 , x3 }, ω(x1 ) = 0, ω(x2 ) = ω(x3 ) = 1 is
equivalent to ω = 011
Example
With ω(x1 ) = ω(x2 ) = 1 and ω(x3 ) = ω(x4 ) = 0
I (x1 ∨ x2 ) ∧ (x3 ∨ x4 ) is not satisfied
Example
With ω(x1 ) = ω(x2 ) = 1 and ω(x3 ) = ω(x4 ) = 0
I (x1 ∨ x2 ) ∧ (x3 ∨ x4 ) is not satisfied
With ω(x1 ) = ω(x3 ) = 1 and ω(x2 ) = ω(x4 ) = 0
I (x1 ∨ x2 ) ∧ (x3 ∨ x4 ) is satisfied
Example
With ω(x1 ) = ω(x3 ) = 1 and ω(x2 ) = ω(x4 ) = 0
I (x1 ∧ x2 ) ∨ (x3 ∧ x4 ) is not satisfied
Example
With ω(x1 ) = ω(x3 ) = 1 and ω(x2 ) = ω(x4 ) = 0
I (x1 ∧ x2 ) ∨ (x3 ∧ x4 ) is not satisfied
With ω(x1 ) = ω(x2 ) = 1 and ω(x3 ) = ω(x4 ) = 0
I (x1 ∧ x2 ) ∨ (x3 ∧ x4 ) is satisfied