Markov Chains: Introduction
Josep Díaz Maria J. Serna Conrado Martínez
U. Politècnica de Catalunya
RA-MIRI 2024–2025
Stochastic Process
A stochastic process is a sequence of random variables
{Xt }n
t=0 .
Usually the subindex t refers to time steps and if t ∈ N, the
stochastic process is said to be discrete.
The random variable Xt is called the state at time t.
If n < ∞ the process is said to be finite, otherwise it is said
infinite.
A stochastic process is used as a model to study the
probability of events associated to a random phenomena.
An example: Gambler’s Ruin
Model used to evaluate insurance risks.
You place bets of 1e. With probability p, you gain 1e, and
with probability q = 1 − p you loose your 1e bet.
You start with an initial amount of 100e.
You keep playing until you loose all your money or you
arrive to have 1000e.
One goal is finding the probability of winning i.e. getting
the 1000e.
Notice in this process, once we get 0e or 1000e, the process
stops.
An example: Gambler’s Ruin
Model used to evaluate insurance risks.
You place bets of 1e. With probability p, you gain 1e, and
with probability q = 1 − p you loose your 1e bet.
You start with an initial amount of 100e.
You keep playing until you loose all your money or you
arrive to have 1000e.
One goal is finding the probability of winning i.e. getting
the 1000e.
Notice in this process, once we get 0e or 1000e, the process
stops.
An example: Gambler’s Ruin
Model used to evaluate insurance risks.
You place bets of 1e. With probability p, you gain 1e, and
with probability q = 1 − p you loose your 1e bet.
You start with an initial amount of 100e.
You keep playing until you loose all your money or you
arrive to have 1000e.
One goal is finding the probability of winning i.e. getting
the 1000e.
Notice in this process, once we get 0e or 1000e, the process
stops.
Markov Chain
One simple model of stochastic process is the Markov Chain:
Markov Chains are defined on a finite set of states (S),
where at time t, Xt could be any state in S, together with
by the matrix of transition probability for going from each
state in S to any other state in S, including the case that the
state Xt remains the same at t + 1.
In a Markov Chain, at any given time t, the state Xt is
determined only by Xt−1 .
memoryless: does not remember the history of past
events,
Other memoryless stochastic processes are said to be
Markovian.
An example: Gambler’s Ruin
You place bets of 1e. With probability p, you gain 1e, and
with probability q = 1 − p you loose your 1e bet.
You start with an initial amount of 100e.
You keep playing until you loose all your money or you
arrive to have 1000e.
We have a state for each possible amount of money you
can accumulate S = {0, 1, . . . , 1000}.
The probability of losing/winning is independent on the
state and the time, so this process is a Markov chain.
Observe that the number of states is finite.
An example: Gambler’s Ruin
You place bets of 1e. With probability p, you gain 1e, and
with probability q = 1 − p you loose your 1e bet.
You start with an initial amount of 100e.
You keep playing until you loose all your money or you
arrive to have 1000e.
We have a state for each possible amount of money you
can accumulate S = {0, 1, . . . , 1000}.
The probability of losing/winning is independent on the
state and the time, so this process is a Markov chain.
Observe that the number of states is finite.
An example: Gambler’s Ruin
You place bets of 1e. With probability p, you gain 1e, and
with probability q = 1 − p you loose your 1e bet.
You start with an initial amount of 100e.
You keep playing until you loose all your money or you
arrive to have 1000e.
We have a state for each possible amount of money you
can accumulate S = {0, 1, . . . , 1000}.
The probability of losing/winning is independent on the
state and the time, so this process is a Markov chain.
Observe that the number of states is finite.
An example: Gambler’s Ruin
You place bets of 1e. With probability p, you gain 1e, and
with probability q = 1 − p you loose your 1e bet.
You start with an initial amount of 100e.
You keep playing until you loose all your money or you
arrive to have 1000e.
We have a state for each possible amount of money you
can accumulate S = {0, 1, . . . , 1000}.
The probability of losing/winning is independent on the
state and the time, so this process is a Markov chain.
Observe that the number of states is finite.
Markov-Chains: An important tool for CS
One of the simplest forms of stochastic dynamics.
Allows to model stochastic temporal dependencies
Applications in many areas
Surfing the web
Design of randomizes algorithms
Random walks
Machine Learning (Markov Decision Processes)
Computer Vision (Markov Random Fields)
etc. etc.
Formal definition of Markov Chains
Definition
A finite, time-discrete Markov Chain, with finite state S =
{1, 2, . . . , k} is a stochastic process {Xt } s.t. for all i, j ∈
S, and for all t > 0,
P[Xt+1 = j | X0 = i0 , X1 = i1 , . . . , Xt = i] = P[Xt+1 = j | Xt = i] .
We can abstract the time and consider only the probability of
moving from state i to state j, as P[Xt+1 = j | Xt = i]
Formal definition of Markov Chains
Definition
A finite, time-discrete Markov Chain, with finite state S =
{1, 2, . . . , k} is a stochastic process {Xt } s.t. for all i, j ∈
S, and for all t > 0,
P[Xt+1 = j | X0 = i0 , X1 = i1 , . . . , Xt = i] = P[Xt+1 = j | Xt = i] .
We can abstract the time and consider only the probability of
moving from state i to state j, as P[Xt+1 = j | Xt = i]
MC: Transition probability matrix
For v, u ∈ S, let pu,v be the probability of going from u v in 1
step i.e. pu,v = P[Xs+1 = v | Xs = u].
P = (pu,v )u,v∈S is a matrix describing the transition
probabilities of the MC
P is called the transition matrix
P also defines digraph, possibly with loops.
A
2/3 1/3
1/2 1/2
1/2
B 1/2 C
MC: Transition probability matrix
For v, u ∈ S, let pu,v be the probability of going from u v in 1
step i.e. pu,v = P[Xs+1 = v | Xs = u].
P = (pu,v )u,v∈S is a matrix describing the transition
probabilities of the MC
P is called the transition matrix
P also defines digraph, possibly with loops.
A
2/3 1/3
1/2 1/2
1/2
B 1/2 C
MC: Transition probability matrix
For v, u ∈ S, let pu,v be the probability of going from u v in 1
step i.e. pu,v = P[Xs+1 = v | Xs = u].
P = (pu,v )u,v∈S is a matrix describing the transition
probabilities of the MC
P is called the transition matrix
P also defines digraph, possibly with loops.
A
2/3 1/3
1/2 1/2
1/2
B 1/2 C
MC: Transition probability matrix
For v, u ∈ S, let pu,v be the probability of going from u v in 1
step i.e. pu,v = P[Xs+1 = v | Xs = u].
P = (pu,v )u,v∈S is a matrix describing the transition
probabilities of the MC
P is called the transition matrix
P also defines digraph, possibly with loops.
A
2/3 1/3
1/2 1/2
1/2
B 1/2 C
Gambler’s Ruin: MC digraph
You place bets of 1e. With probability p, you gain 1e, and
with probability q = 1 − p you loose your 1e bet.
You start with an initial amount of i e and keep playing until
you loose all your money or you arrive to have n e.
We have a state for each possible amount of money you
can accumulate S = {0, 1, . . . , n}.
1 q q q q 1
q p
0 1 i−1 i i+1 n−1 n
p p p p
Initial State
Absorbing States
Gambler’s Ruin: MC digraph
You place bets of 1e. With probability p, you gain 1e, and
with probability q = 1 − p you loose your 1e bet.
You start with an initial amount of i e and keep playing until
you loose all your money or you arrive to have n e.
We have a state for each possible amount of money you
can accumulate S = {0, 1, . . . , n}.
1 q q q q 1
q p
0 1 i−1 i i+1 n−1 n
p p p p
Initial State
Absorbing States
Transition matrix: Example
A B C
A A 0 2/3 1/3
2/3 1/3
1/2 1/2 B 1/2 0 1/2 =P
1/2
B 1/2 C C 1/2 0 1/2
Notice the entry (u, v) in P denotes the probability of going from
u → v in one step.
Notice, in a MC the transition matrix is stochastic, so sum of
transitions out of any state must be 1 = sum of the elements of
any row of the transition matrix must be 1
Longer transition probabilities
(t)
For u, v ∈ S, let pu,v be the probability of going from u v in
(t)
exactly t steps i.e. pu,v = P[Xs+t = v | Xs = u].
(t)
Formally for s > 0 and t > 1, pu,v = P[Xs+t = v | Xs = u].
(1)
Notice that pu,v = pu,v ; we shall use P(t) for the matrix whose
(t)
entries are the values pu,v , and P(1) = P.
How can we relate P(t) with P?
The powers of the transition matrix
A B C
A A 0 2/3 1/3
2/3 1/3
1/2 1/2 B 1/2 0 1/2 =P
1/2
B 1/2 C C 1/2 0 1/2
(1)
In ex. P[X1 = C|X0 = A] = PA,C = 1/3.
(1) (1) (1) (1) (2)
P[X2 = C|X0 = A] = PAB PBC + PAC PCC = 1/3 + 1/6 = PA,C
In general, assume a MC with k states and transition matrix P,
let u, v ∈ S:
• What is the P[X1 = v|X0 = u], i.e. = pu,v ?
(2)
• What is the P[X2 = v|X0 = u] = pu,v ?
The powers of the transition matrix
Use Law Total Probability+ Markov property:
(2)
X
m
Pu,v = P[X2 = v|X0 = u] = P[X1 = w|X0 = u] P[X2 = v|X1 = w]
w=1
X
m
= Pu,w Pw,v .
w=1
The powers of the transition matrix
In general
(t)
pu,v = P[Xt = v|X0 = u]
Xm
= P[Xt−1 = w|X0 = u] P[Xt = v|Xt−1 = w]
w=1
Xm
(t−1)
= Pu,w Pw,u .
w=1
Lemma
Given the transition matrix P of a MC, then for any t >
1,
P(t) = P(t−1) · P
With the convention P(0) = I (the identity matrix), we
have
P(t) = Pt ,
for any t > 0.
Distributions at time t
To fix the initial state, we consider a random variable X0 ,
assigning to S an initial distribution π0 , which is a row vector
indicating at t = 0 the probability of being in the corresponding
state.
For example, in the MC:
A
2/3 1/3
1/2 1/2
1/2
B 1/2 C
we may consider,
A B C
(0 0.4 0.6) = π0
Distributions at time t
Starting with an initial distribution π0 , we can compute the state
distribution πt (on S) at time t,
For a state v,
πt [v] = P[Xt = v]
X
= P[X0 = u] P[Xt = v|X0 = u]
u∈S
X (t)
= π0 [u]Pu,v .
u∈S
where πt [y] is the probability that the system is in state y at
time t.
Therefore, πt = π0 Pt and πs+t = πs Pt .
Gambler’s Ruin: Exercise
You place bets of 1e. With probability p, you gain 1e, and
with probability q = 1 − p you loose your 1e bet.
You start with an initial amount of i e and keep playing until
you loose all your money or you arrive to have n e.
We have a state for each possible amount of money you
can accumulate S = {0, 1, . . . , n}.
Which is the initial distribution π0 ?
And, the state distribution at time t = 3?
Gambler’s Ruin: Exercise
You place bets of 1e. With probability p, you gain 1e, and
with probability q = 1 − p you loose your 1e bet.
You start with an initial amount of i e and keep playing until
you loose all your money or you arrive to have n e.
We have a state for each possible amount of money you
can accumulate S = {0, 1, . . . , n}.
Which is the initial distribution π0 ?
And, the state distribution at time t = 3?
Example MC: Writing a research paper
Recall that Markov Chains are given either by a weighted
digraph, where the edge weights are the transition probabilities,
or by the |S| × |S| transition probability matrix P,
Example: Writing a paper S = {k, w, e, s}
0.5 0.5
0.3
k w e s
Think 0.2 Write k 0.5 0.3 0 0.2
0.2 0.2 w 0.2 0.5 0.1 0.2
0.2 0.3 e 0.1 0.3 0.3 0.3
0.1
0.1 s 0 0.2 0.3 0.5
Surf 0.3 e−mail
0.3
0.5 0.3
More on the Markovian property
Notice the memoryless property does not mean that Xt+1 is
independent from X0 , X1 , . . . , Xt−1 .
(For instance notice that intuitively we have:
P[Thinking at t + 1] < P[Thinking at t | Thinking at t − 1]).
But, the dependencies of Xt on X0 , . . . , Xt−1 , are all captured
by Xt−1 .
0.5 0.5
0.3
Think 0.2 Write
0.2 0.2 0.2
0.1 0.3
0.1
Surf 0.3 e−mail
0.3
0.5 0.3
Example of writing a paper
P[X2 = k|X0 = s] is the probability that, at t = 2, we are in state
k (think), starting in state s (surf).
0.5 0.3 0 0.2 0.5 0.3 0 0.2 0.31 0.34 0.09 0.26
0.2 0.5 0.1 0.2 0.2 0.5 0.1 0.2 = 0.21 0.38 0.14 0.27
0.1 0.3 0.3 0.3 0.1 0.3 0.3 0.3 0.14 0.33 0.21 0.32
0 0.2 0.3 0.5 0 0.2 0.3 0.5 0.07 0.29 0.26 0.38
P[X2 = k|X0 = s] = 0.07.
Distribution on states
Recall πt is the prob. distribution at time t over S.
For our example of writing a paper, if t = 0 (after waking up):
k w e s
π0 = (0.2 0 0.3 0.5)
0.5 0.3 0 0.2
0.2 0.5 0.1 0.2
0.2 0 0.3 0.5 0.1
= 0.13 0.25 0.24 0.38 = π1
0.3 0.3 0.3
0 0.2 0.3 0.5
Therefore, we have πt = π0 × Pt and πk+t = πk × Pt
Notice πt = (πt [r], πt [w], πt [e], πt [s])
An Example of MC analysis: The 2-SAT problem
Section 7.1 of [MU].
Given a Boolean formula φ, on
• a set X of n Boolean variables,
• defined by m clauses C1 , . . . Cm , where each clause is the
disjunction of exactly 2 literals, (xi or x̄i ), on different variables.
• φ = conjunction of the m clauses.
The 2-SAT problem is to find an assignment A∗ : X → {0, 1},
which satisfies φ,
i.e, to find an A∗ s.t. A∗ (φ) = 1.
Notice that if |X| = n, then m 6 2n 2
2 = O(n ).
In general k-SAT∈ NP-complete, for k > 3. But 2-SAT∈ P.
A randomized algorithm for 2-SAT
Given a n variable 2-SAT formula φ, {Cj }mj=1
for 1 6 i 6 n do
A(xi ) := 1
end for
t := 0
while t 6 2cn2 and some clause is unsatisfied do
Pick and unsatisfied clause Cj
Choose u.a.r. one of the 2 variables in Cj and flip its value
if φ is satisfied then
return A
end if
end while
return φ is unsatisfiable
An example: unsat formula
If φ = (x1 ∨ x2 ) ∧ (x̄1 ∨ x̄2 ) ∧ (x̄1 ∨ x2 ) ∧ (x1 ∨ x̄2 )
does not has a A∗ |= φ.
t x1 x2 sel clause
1 1 1 2
2 1 0 3
3 0 0 1
.. .. .. ..
. . . .
φ is unsat eventually the algorithm will stop after reaching the
maximum number of steps.
An example: unsat formula
If φ = (x1 ∨ x2 ) ∧ (x̄1 ∨ x̄2 ) ∧ (x̄1 ∨ x2 ) ∧ (x1 ∨ x̄2 )
does not has a A∗ |= φ.
t x1 x2 sel clause
1 1 1 2
2 1 0 3
3 0 0 1
.. .. .. ..
. . . .
φ is unsat eventually the algorithm will stop after reaching the
maximum number of steps.
An example: unsat formula
If φ = (x1 ∨ x2 ) ∧ (x̄1 ∨ x̄2 ) ∧ (x̄1 ∨ x2 ) ∧ (x1 ∨ x̄2 )
does not has a A∗ |= φ.
t x1 x2 sel clause
1 1 1 2
2 1 0 3
3 0 0 1
.. .. .. ..
. . . .
φ is unsat eventually the algorithm will stop after reaching the
maximum number of steps.
An example: unsat formula
If φ = (x1 ∨ x2 ) ∧ (x̄1 ∨ x̄2 ) ∧ (x̄1 ∨ x2 ) ∧ (x1 ∨ x̄2 )
does not has a A∗ |= φ.
t x1 x2 sel clause
1 1 1 2
2 1 0 3
3 0 0 1
.. .. .. ..
. . . .
φ is unsat eventually the algorithm will stop after reaching the
maximum number of steps.
An example: unsat formula
If φ = (x1 ∨ x2 ) ∧ (x̄1 ∨ x̄2 ) ∧ (x̄1 ∨ x2 ) ∧ (x1 ∨ x̄2 )
does not has a A∗ |= φ.
t x1 x2 sel clause
1 1 1 2
2 1 0 3
3 0 0 1
.. .. .. ..
. . . .
φ is unsat eventually the algorithm will stop after reaching the
maximum number of steps.
An example: unsat formula
If φ = (x1 ∨ x2 ) ∧ (x̄1 ∨ x̄2 ) ∧ (x̄1 ∨ x2 ) ∧ (x1 ∨ x̄2 )
does not has a A∗ |= φ.
t x1 x2 sel clause
1 1 1 2
2 1 0 3
3 0 0 1
.. .. .. ..
. . . .
φ is unsat eventually the algorithm will stop after reaching the
maximum number of steps.
An example: sat formula
If φ = (x1 ∨ x̄2 ) ∧ (x̄1 ∨ x̄3 ) ∧ (x̄1 ∨ x2 ) ∧ (x̄4 ∨ x̄3 ) ∧ (x4 ∨ x̄1 )
t x1 x2 x3 x4 sel clause
1 1 1 1 1 2
2 0 1 1 1 1
3 0 0 1 1 4
4 0 0 1 0 –
(0, 0, 1, 0) satisfies φ
An example: sat formula
If φ = (x1 ∨ x̄2 ) ∧ (x̄1 ∨ x̄3 ) ∧ (x̄1 ∨ x2 ) ∧ (x̄4 ∨ x̄3 ) ∧ (x4 ∨ x̄1 )
t x1 x2 x3 x4 sel clause
1 1 1 1 1 2
2 0 1 1 1 1
3 0 0 1 1 4
4 0 0 1 0 –
(0, 0, 1, 0) satisfies φ
An example: sat formula
If φ = (x1 ∨ x̄2 ) ∧ (x̄1 ∨ x̄3 ) ∧ (x̄1 ∨ x2 ) ∧ (x̄4 ∨ x̄3 ) ∧ (x4 ∨ x̄1 )
t x1 x2 x3 x4 sel clause
1 1 1 1 1 2
2 0 1 1 1 1
3 0 0 1 1 4
4 0 0 1 0 –
(0, 0, 1, 0) satisfies φ
An example: sat formula
If φ = (x1 ∨ x̄2 ) ∧ (x̄1 ∨ x̄3 ) ∧ (x̄1 ∨ x2 ) ∧ (x̄4 ∨ x̄3 ) ∧ (x4 ∨ x̄1 )
t x1 x2 x3 x4 sel clause
1 1 1 1 1 2
2 0 1 1 1 1
3 0 0 1 1 4
4 0 0 1 0 –
(0, 0, 1, 0) satisfies φ
An example: sat formula
If φ = (x1 ∨ x̄2 ) ∧ (x̄1 ∨ x̄3 ) ∧ (x̄1 ∨ x2 ) ∧ (x̄4 ∨ x̄3 ) ∧ (x4 ∨ x̄1 )
t x1 x2 x3 x4 sel clause
1 1 1 1 1 2
2 0 1 1 1 1
3 0 0 1 1 4
4 0 0 1 0 –
(0, 0, 1, 0) satisfies φ
An example: sat formula
If φ = (x1 ∨ x̄2 ) ∧ (x̄1 ∨ x̄3 ) ∧ (x̄1 ∨ x2 ) ∧ (x̄4 ∨ x̄3 ) ∧ (x4 ∨ x̄1 )
t x1 x2 x3 x4 sel clause
1 1 1 1 1 2
2 0 1 1 1 1
3 0 0 1 1 4
4 0 0 1 0 –
(0, 0, 1, 0) satisfies φ
An example: sat formula
If φ = (x1 ∨ x̄2 ) ∧ (x̄1 ∨ x̄3 ) ∧ (x̄1 ∨ x2 ) ∧ (x̄4 ∨ x̄3 ) ∧ (x4 ∨ x̄1 )
t x1 x2 x3 x4 sel clause
1 1 1 1 1 2
2 0 1 1 1 1
3 0 0 1 1 4
4 0 0 1 0 –
(0, 0, 1, 0) satisfies φ
An example: sat formula
If φ = (x1 ∨ x̄2 ) ∧ (x̄1 ∨ x̄3 ) ∧ (x̄1 ∨ x2 ) ∧ (x̄4 ∨ x̄3 ) ∧ (x4 ∨ x̄1 )
t x1 x2 x3 x4 sel clause
1 1 1 1 1 2
2 0 1 1 1 1
3 0 0 1 1 4
4 0 0 1 0 –
(0, 0, 1, 0) satisfies φ
Analysis for 2-SAT algorithm
Given φ, |X| = n, {Cj }m
i=1
assume that there is A∗ such that φ(A∗ ) = 1
Let Ai be the assignment at the i-th iteration.
Let Xi = |{xj ∈ X | Ai (xj ) = A∗ (xj )}.
Notice 0 6 Xi 6 n. Moreover, when Xi = n, we found A∗ .
Analysis: Starting from Xi < n, how long to get Xi = n?
Note that P[Xi+1 = 1 | Xi = 0] = 1.
Analysis for 2-SAT algorithm
As A∗ satisfies φ and Ai no, there is a clause Cj that A∗
satisfies but Ai not.
So A∗ and Ai disagree in the value of at least one variable.
It is also possible to flip the value of a variable in Cj in
which A and A∗ agree.
Therefore,
For 1 6 k 6 n − 1, P[Xi+1 = k + 1 | Xi = k] > 1/2 and
P[Xi+1 = k − 1 | Xi = k] 6 1/2.
Analysis for 2-SAT
The process X0 , X1 , . . . is not necessarily a MC,
The probability that Xi+1 > Xi depends on whether Ai and
A∗ disagree in 1 or 2 variables in the selected unsatisfied
clause C.
If A∗ makes true both literals in C,
P[Xi+1 = k + 1 | Xi = k] = 1, otherwise
P[Xi+1 = k + 1 | Xi = k] = 1/2
This difference might depend on the clauses and variables
selected in the past, so the transition probabilities are not
memoryless.
Xt is not a Markov chain. Can we bound the process by a
MC?.
Analysis for 2-SAT
The process X0 , X1 , . . . is not necessarily a MC,
The probability that Xi+1 > Xi depends on whether Ai and
A∗ disagree in 1 or 2 variables in the selected unsatisfied
clause C.
If A∗ makes true both literals in C,
P[Xi+1 = k + 1 | Xi = k] = 1, otherwise
P[Xi+1 = k + 1 | Xi = k] = 1/2
This difference might depend on the clauses and variables
selected in the past, so the transition probabilities are not
memoryless.
Xt is not a Markov chain. Can we bound the process by a
MC?.
Analysis for 2-SAT
Define a MC Y0 , Y1 , Y2 , . . . which is a pessimistic version of
process X0 , X1 , . . ., in the sense that Yi measures exactly the
same quantity than Xi but the probability of change (up or
down) will be exactly 1/2.
Y0 = X0 and P[Yi+1 = 1 | Yi = 0] = 1;
For 1 6 k 6 n − 1, P[Yi+1 = k + 1 | Yi = k] = 1/2;
P[Yi+1 = k − 1 | Yi = k] = 1/2.
1 1/2 1/2 1/2 1/2 1/2
0 1 2 j n−1 1/2 n 1
1/2 1/2 1/2 1/2 1/2 1/2
MC for 2−SAT
The time to reach n from j > 0 in {Yi }n
i=0 is > that in {Xi }i=0 .
n
Upper Bound on the time to arrive state n
Lemma
If a 2-CNF φ on n variables has a satisfying assignment
A∗ , the 2-SAT algorithm finds one in expected time
6 n2 .
Proof
Let hj be the expected time, for process Y, to go
from state j to state n.
It suffices to prove that, when Y starts in state j the
time to arrives to n is 6 2cn2 .
We devise a recurrence to bound h
Upper Bound on the time to arrive state n
Proof (cont’d)
hn = 0 and h1 = h0 + 1;
We want a general recurrence on hj , for 1 6 j < n
Define a rv Zj counting the steps to go from state
j → n in Y.
With probability 1/2, Zj = Zj−1 + 1 and, with
probability 1/2, Zj = Zj+1 + 1.
So hj = E Zj .
Zj−1 + 1 Zj+1 + 1 E[Zj−1 ] + 1 E[Zj+1 ] + 1
E[Zj ] = E + = + .
2 2 2 2
hj−1 hj+1
So, hj = 2 + 2 + 1.
Upper Bound on the time to arrive state n
Proof (cont’d)
hj−1 hj+1
From the previous bound we get hj = 2 + 2 + 1.
The recurrence has the n + 1 equations,
hn =0
h0 =h1 + 1
hj−1 hj+1
hj = + +1 06j6n−1
2 2
Let us prove, by induction that
hj = hj+1 + 2j + 1.
Upper Bound on the time to arrive state n
Proposition
For 0 6 j 6 n − 1, hj = hj+1 + 2j + 1.
Proof (of Proposition)
Base case: If j = 0, 2j + 1 = 1, and we were given h0 =
h1 + 1.
Upper Bound on the time to arrive state n
Proposition
For 0 6 j 6 n − 1, hj = hj+1 + 2j + 1.
Proof of Proposition (cont’d)
IH: forj = k − 1, hk−1 = hk + 2(k − 1) + 1.
Now consider j = k. By the “middle case” of our system
of equations,
hk−1 + hk+1
hk = +1
2
hk + 2(k − 1) + 1 hk+1
= + +1 by IH
2 2
hk hk+1 2k + 1
= + +
2 2 2
hk
Subtracting 2 from each side, we get the result.
Upper Bound on the time to arrive state n
Proof (cont’d)
As
hj = hj+1 + 2j + 1.
h0 = h1 + 1 = h 2 + 3 + 1 = h 3 + 5 + 3 + 1 · · ·
X
n−1
= hn + (2i + 1) = n2 .
|{z}
=0 i=0
Error probability for 2-SAT algorithm
Theorem
The 2-SAT algorithm gives the correct answer NO if φ is
not satisfiable. Otherwise, with probability > 1 − 21c the
algorithm returns a satisfying assignment.
Error probability for 2-SAT algorithm
Proof
Let φ be satisfiable (otherwise the theorem holds).
Break the 2cn2 iterations into c blocks of 2n2
iterations.
For each block i, define a r.v. Z = number of
iterations from the start of the i-block until a
solution is found.
Using Markov’s inequality:
h
2
i n2 1
P Z > 2n 6 2
= .
2n 2
Therefore, the probability that the algorithm fails to
find a satisfying assignment after c segments (no
block includes a solution) is at most 21c .