Appendix B
Algorithms

Here we adopt a standard notation (pseudocode) for defining algorithms [33154]. Assignment of a value α to a variable β is denoted by β α. The branching probability Pα,β is represented as P[α,β] if it is stored in matrix form, and as P[β][α] if it is stored in the form of adjacency lists.

Algorithm B.1:Calculate the pathway sum 𝒮α,βCN
  Require:  Chain nodes are numbered 0,1,2,,N 1   Require:  1 < N   Require:  α,β {0,1,2,,N 1}   Require:  P[i,j] is the probability of branching from node j to node i    1: if α < β then
   2:  h 1; t N 2; s 1

   3: else
   4:  h N 2; t 1; s 1

   5: end if
   6:  L 1
   7: for all i {h,h + s,h + 2s,,α} do
   8:  L 1(1 P[i s,i]P[i,i s]L)

   9: end for
   10:  Π 1
   11: for all i {α + s,α + 2s,α + 3s,,β} do
   12:  Π P[i s,i]
   13:  L 1(1 P[i s,i]P[i,i s]L)

   14: end for
   15:  R 1
   16: for all i {t,t s,t 2s,,β} do
   17:  R 1(1 P[i + s,i]P[i,i + s]R)

   18: end for
   19: return  LRΠ(L LR + R)

Algorithm B.2:Calculate the pathway sum 𝒮a,bGN
  Require:  1 < N   Require:  a,b {0,1,2,,N 1}   Require:  W is a boolean array of size N with every element initially set to True   Require:  NW is the number of True elements in array W (initialised to N)   Require:  P[i,j] is the probability of branching from node j to node i   Require:  AdjIn[i] and AdjOut[i] are the lists of indices of all nodes connected to node i via incoming and outgoing edges, respectively Recursive function F(α,β,W,NW )    1:  W[β] False
   2:  NW NW 1
   3: if α = β and NW = 0 then
   4:  Σ 1

   5: else
   6:  Σ 0.0
   7: for all i AdjOut[β] do
   8: for all j AdjIn[β] do
   9: if W[i] and W[j] then
   10:  Σ Σ + P[β,j]F(j,i,W,NW )P[i,β]

   11: end if

   12: end for

   13: end for
   14:  Σ 1(1 Σ)
   15: if αβ then
   16:  Λ 0.0
   17: for all i AdjOut[β] do
   18: if W[i] then
   19:  Λ Λ + F(α,i,W,NW )P(i,β)

   20: end if

   21: end for
   22:  Σ ΣΛ

   23: end if

   24: end if
   25:  W[β] True
   26:  NW NW + 1
   27: return  Σ

Algorithm B.3:Calculate the pathway sum 𝒮α,β𝒢N from every source to every sink, and the mean escape time for every source in a dense graph 𝒢N
  Require:  Nodes are numbered 0,1,2,,N 1   Require:  Sink nodes are indexed first, source nodes - last   Require:  i is the index of the first intermediate node   Require:  s is the index of the first source node   Require:  In case there are no intermediate nodes i = s, otherwise i < s   Require:  1 < N   Require:  i,s {0,1,2,,N 1}   Require:  τ[α] is the waiting time for node α, α {i,i + 1,i + 2,,N 1}   Require:  P[i,j] is the probability of branching from node j to node i    1: for all γ {i,i + 1,i + 2,,s 1} do
   2: for all β {γ + 1,γ + 2,,N 1} do
   3: if P[γ,β] > 0 then
   4:  τ[β] (τ[β] + τ[γ]P[γ,β])(1 P[β,γ]P[γ,β])
   5: for all α {0,1,2,,N 1} do
   6: if αβ and αγ then
   7:  P[α,β] (P[α,β] + P[α,γ]P[γ,β])(1 P[β,γ]P[γ,β])

   8: end if

   9: end for
   10:  P[γ,β] 0.0

   11: end if

   12: end for
   13: for all α {0,1,2,,N 1} do
   14:  P[α,γ] 0.0

   15: end for

   16: end for
   17: for all α {s,s + 1,s + 2,,N 1} do
   18: for all β {s,s + 1,s + 2,,N 1} do
   19: if αβ and P[α,β] > 0 then
   20:  Pα,β P[α,β]
   21:  Pβ,α P[β,α]
   22:  T τ[α]
   23:  τ[α] (τ[α] + τ[β]Pβ,α)(1 Pα,βPβ,α)
   24:  τ[β] (τ[β] + TPα,β)(1 Pα,βPβ,α)
   25: for all γ {0,1,2,,i 1}{s,s + 1,s + 2,,N 1} do
   26:  T P[γ,α]
   27:  P[γ,α] (P[γ,α] + P[γ,β]Pβ,α)(1 Pα,βPβ,α)
   28:  P[γ,β] (P[γ,β] + TPα,β)(1 Pα,βPβ,α)

   29: end for
   30:  P[α,β] 0.0
   31:  P[β,α] 0.0

   32: end if

   33: end for

   34: end for

Algorithm B.4:Detach node γ from an arbitrary graph 𝒢N
  Require:  1 < N   Require:  γ {0,1,2,,N 1}   Require:  τ[i] is the waiting time for node i   Require:  Adj[i] is the ordered list of indices of all nodes connected to node i via outgoing edges   Require:  |Adj[i]| is the cardinality of Adj[i]   Require:  Adj[i][j] is the index of the jth neighbour of node i   Require:  P[i] is the ordered list of probabilities of leaving node i via outgoing edges, |P[i]| = |Adj[i]|   Require:  P[i][j] is the probability of branching from node i to node Adj[i][j]    1: for all βγ {0,1,2,,|Adj[γ]| 1} do
   2:  β Adj[γ][βγ]
   3:  γβ 1
   4: for all i {0,1,2,,|Adj[β]| 1} do
   5: if Adj[β][i] = γ then
   6:  γβ i
   7: break

   8: end if

   9: end for
   10: if not γβ = 1 then
   11:  Pβ,β 1(1 P[β][γβ]P[γ][βγ])
   12:  Pβ,γ P[β][γβ]
   13:  Adj[β] {Adj[β][0],Adj[β][1],,Adj[β][γβ 1],Adj[β][γβ + 1],}
   14:  P[β] {P[β][0],P[β][1],,P[β][γβ 1],P[β][γβ + 1],}
   15: for all αγ {0,1,2,,|Adj[γ]| 1} do
   16:  α Adj[γ][αγ]
   17: if not α = β then
   18: if exists edge β α then
   19: for all i {0,1,2,,|Adj[β]| 1} do
   20: if Adj[β][i] = α then
   21:  P[β][i] P[β][i] + Pβ,γP[γ][αγ]
   22: break

   23: end if

   24: end for

   25: else
   26:  Adj[β] {α,Adj[β][0],Adj[β][1],Adj[β][2],}
   27:  P[β] {Pβ,γP[γ][αγ],P[β][0],P[β][1],P[β][2],}

   28: end if

   29: end if

   30: end for
   31: for all i {0,1,2,,|P[β]| 1} do
   32:  P[β][i] P[β][i]Pβ,β

   33: end for
   34:  τβ τβ + Pβ,γτγ Pβ,β

   35: end if

   36: end for