SlideShare une entreprise Scribd logo
1  sur  38
Algorithm Design and Complexity

                         Course 11
Overview
   All-Pairs Shortest Paths (APSP)
   Using SSSP Algorithms
   Simple DP Algorithms
   Floyd-Warshall Algorithm
   Johnson’s Algorithm
   Transitive Closure of a Graph
All-Pairs Shortest Paths (APSP)
   G(V, E) (un)directed, connected and weighted graph
   The weight (cost) function w: E → R
   w(u, v) = the weight of the edge (u, v)

   Adjacency matrix of weights
   W = [w(i, j)] ; 1 <= i, j <= n
       w(i, j) = 0                            if i = j
       w(i, j) = INF                                     if i != j and (i, j)E
       w(i, j) = weight of the edge (i, j)    if i != j and (i, j)E

   Compute the shortest paths between any two vertices in the
    graph
   Use a matrix D = [d(i, j)] ; 1 <= i, j <= n
       We want d(i, j) = δ(i, j) = weight of the shortest path from i to j
APSP – Predecessors
   We also compute a matrix of predecessors
   P = [p(i, j)] ; 1 <= i, j <= n
       p(i, j) is the predecessor of j on the shortest path i..j
       p(i, j) = NIL if there isn’t any path between i and j

   Therefore to find out the vertices on the shortest path
    between any two vertices, u and v, u..v:
       1. Start from v’ = v
       2. Go to v’ = p(u, v’)
       3. If (v’ == u) then stop
       4. Else go to step 2

   (p(u,v), v), (p(u, p(u,v)), p(u,v))… (u, p(u, … p(u,v)))
Solutions for APSP
1.       Use SSSP algorithms called n times
         Considering each vertex as a source
2.       Use specialized algorithms
         Try to compute the matrices D and P directly


        There is no algorithm that works best for all cases
        Consider the best choice given the problem
         needed to be solved
         Dense vs. sparse graph, negative vs. positive weights
         Special cases: DAGs
         Etc.
Using SSSP Algorithms for APSP
   For any type of graph
   Use Bellman-Ford – n times
       n * (n*m) = (n2*m)
       Dense graphs: (n4)
       Sparse graphs: (n3)
       We want to improve it!
   Using Dijkstra – n times
       Only for positive weighted edges
       Fibonacci heaps: n * (n*logn + m) = (n2*logn + n*m)
       Dense graphs: (n3)
       Sparse graphs: (n2*logn)
       Otherwise, choose between binary heap and arrays for the best
        solution depending on the graph
Specific APSP Algorithms
   The specific APSP algorithms, should work better than
    the previous solutions
   We want (n3) for any kind of graph
       Floyd-Warshall algorithm
   Maybe find improvements for specific types of graphs
       (n2*logn) for sparse graphs with negative weights
       Johnson’s algorithm
   For some graphs, the SSSP solutions is the best one
       E.g. for DAGS, the SSSP algorithm works great with minor
        improvements
   Use dynamic programming for designing these
    algorithms
APSP DP Algorithms
    Use the property: any subpath of a shortest path is
     also a shortest path!
    What kind of sub-problems?

1.    Determine the shortest paths that contain at most k
      edges! (Simple DP algorithms)
2.    Determine the shortest paths that contain only the
      first k vertices as intermediate vertices on the SP
      (Floyd-Warshall algorithm)

     Start with k = 0 and then increase it!
Simple DP algorithms
   Compute the APSP that contain at most k edges on
    the determined SP!
   Use L(k)[i, j] = the weight of the SP from vertex i to
    vertex j that contains <= k edges
   Start with k = 0 (stop condition for the recursion)
       L(0)[i, j] = 0      if i = j
       L(0)[i, j] = INF    if i != j
   Use the following recursion for k >= 1
   L(k)[i, j]
        = min(L(k-1)[i, j] , mink=1..n(L(k-1)[i, k] + w(k, j)))
        = mink=1..n(L(k-1)[i, k] + w(k, j))       because w(j, j) = 0
Simple DP Algorithm for APSP
   Can also compute the predecessor matrix as well
       Exercise: how to compute it!


   Verify the recursive formula when k = 1
   L(1)[i, j] should be w(i, j)

   But
    L(1)[i, j]   = mink=1..n(L(0)[i, k] + w(k, j))
                 = L(0)[i, i] + w(i, j) (the only non-INF value)
                 = w(i, j)
Simple DP Algorithm for APSP (2)
   There are at most n – 1 edges on each shortest path
   Therefore, we want to compute L(n-1)
   Afterwards, the matrix should not change anymore:
    L(n-1) = L(n) = L(n+1) = …
    δ(i, j) = L(n-1)[i, j] = L(n)[i, j] = L(n+1)[i, j]= …
   Start from L(1) = W
   Compute the solution in a bottom-up manner
   L(1), L(2), …, L(k), …, L(n-1)
Simple DP Algorithm – Pseudocode
SLOW-APSP(G, W)
   n = |V[G]|
   L[1] = W
   FOR (m=2; m < n; m++)
             L[m] = EXPAND(L[m-1], W, n)
   RETURN L[n-1]
EXPAND (L, W, n)
   L’ = new matrix(n, n)
   FOR (i=1; i <= n; i++)
             FOR (j=1; j <= n; j++)
                          L’[i][j] = INF
                          FOR (k=1; k <= n; k++)
                                         L’[i][j] = min(L’[i][j], L[i][k] + w[k][j])
   RETURN L’


Time complexity:
   EXPAND - (n3)
   SLOW-APSP - (n4)  not very good! Same as Bellman-Ford - n times!

Space complexity: uses n matrices - (n3)  can be reduced by using the same matrix L
Improved Simple DP Algorithm
   Improve the way L(n-1) is computed
   Instead of computing:
         L(1), L(2), …, L(k), …, L(n-1)
   Why not compute?
         L(1), L(2), L(4), …, L(2^k), …, L(2^r)
   Stop when r = ceiling(log(n-1)) >= n-1, but this is ok!

   EXPAND is similar to matrix multiplication C = A * B
       L       A
       W       B
       L’      C
       min     +
       +       *
       INF     0
Improved DP Algorithm – Pseudocode
FAST-APSP(G, W)
   n = |V[G]|
   L[1] = W
   m=1
   FOR (; m < n; m=2*m)
             L[2*m] = EXPAND(L[m], L[m], n)
   RETURN L[m]
EXPAND (L, W, n)
   L’ = new matrix(n, n)
   FOR (i=1; i <= n; i++)
             FOR (j=1; j <= n; j++)
                          L’[i][j] = INF
                          FOR (k=1; k <= n; k++)
                                         L’[i][j] = min(L’[i][j], L[i][k] + w[k][j])
   RETURN L’


Time complexity:
   EXPAND - (n3)
   FAST-APSP - (n3 * logn)  Still not very good! But better than Bellman-Ford - n times!

Space complexity: uses n matrices - (n3)  can be reduced by using the same matrix L
Floyd-Warshall Algorithm
   Use another DP formulation
   Given a path p = <v1, v2, … , vj>
       Any vertex except v1 and vj are intermediate vertices


   Sub-problem: which is the shortest path between
    any two vertices that contain intermediate vertices in
    the set {1, 2, … , k} ?
   D(k) = (D(k) [i, j]) for all 1 <= i, j <= n

   We want to compute D(n)
Floyd-Warshall – Recursive Formulation
   Initialization (stop condition for the recursion):
   D(0) = W
   If no intermediate vertices are allowed, the best path
    between any two vertices is either the weight of the edge
    (if it exists) or INF

   Recursive formulation:
    D(k)[i, j] = min(D(k-1)[i, j], D(k-1)[i, k] + D(k-1)[k, j])
   Choose between:
       The shortest path between i and j that contains intermediate
        vertices in {1, 2, … , k-1}
       The sum of the shortest paths from i to k and from k to j that
        contain intermediate vertices in {1, 2, … , k-1}
Floyd-Warshall – Recursive Formulation
   The recursive formulation can be proved by
    induction
       On whiteboard
   Can also compute P(k)
       How?
   Compute the solution in a bottom-up fashion
   D(0), D(1),…, D(k),…, D(n)
Floyd-Warshall – Pseudocode
FLOYD-WARSHALL(G, W)
   n = |V[G]|
   D[0] = W
   FOR (i = 1; i <= n; i++)
                FOR (j = 1; j <= n; j++)
                                 IF (w(i, j) != INF)
                                                   P[0][i][j] = i
                                 ELSE
                                                   P[0][i][j] = NIL
   FOR (k = 1; k <= n; k++)
                FOR (i = 1; i <= n; i++)
                                 FOR (j = 1; j <= n; j++)
                                                   IF (D[k-1][i][j] < D[k-1][i][k] + D[k-1][k][j])
                                                                       D[k][i][j] = D[k-1][i][j]
                                                                       P[k][i][j] = P[k-1][i][j]
                                                   ELSE
                                                                       D[k][i][j] = D[k-1][i][k] + D[k-1][k][j]
                                                                       P[k][i][j] = P[k-1][k][j]
   RETURN D[n]


Time complexity: (n3)  good for dense graphs and for graphs with negative weights
Space complexity: (n3)  can be reduced to (n2) by using a single D matrix and a single P matrix
Example (1)

                                                 0          3       8 ∞         -4
               2
       3                   4                     ∞          0       ∞ 1         7
           7
               8
                                          D(0) = ∞          4       0 ∞         ∞
 1                              3                2          ∞       -5 0        ∞
  -4               2
                       1                         ∞          ∞       ∞ 6         0
                               -5
       5               4
               6                                 nil          1     1     nil   1
                                                 nil         nil    nil   2     2
                                          P(0) = nil          3     nil   nil   nil
                                                 4           nil     4    nil   nil
                                                 nil         nil    nil   5     nil


                                    Proiectarea Algoritmilor 2010
Example (2)
   0      3     8 ∞         -4                              0          3      8 ∞         -4
   ∞      0     ∞ 1         7                               ∞          0      ∞ 1         7
D= ∞      4     0 ∞         ∞                            D= ∞          4      0 ∞         ∞
   2      ∞     -5 0        ∞                               2          5      -5 0        -2
                                              2
   ∞      ∞     ∞ 6         0          3               4    ∞          ∞      ∞ 6         0
                                            7 8
                                  1                        3
           D(0), P(0)                                                      D(1), P(1)
                                  -4                  1
                                                  2       -5
    nil    1    1     nil   1           5
                                              6
                                                      4       nil       1     1     nil   1
    nil   nil   nil   2     2                                 nil      nil    nil   2     2
p = nil    3    nil   nil   nil                           p = nil       3     nil   nil   nil
    4     nil    4    nil   nil                               4         1      4    nil   1
    nil   nil   nil   5     nil                               nil      nil    nil   5     nil
                                       Proiectarea Algoritmilor 2010
Example (3)
   0      3     8     ∞     -4                              0          3      8 4         -4
   ∞      0     ∞     1     7                               ∞          0      ∞ 1         7
D= ∞      4     0     ∞     ∞                            D= ∞          4      0 5         11
   2      5     -5    0     -2                              2          5      -5 0        -2
                                               2
   ∞      ∞     ∞     6     0           3               4   ∞          ∞      ∞ 6         0
                                             7 8
                                  1                         3
           D(1), P(1)                                                      D(2), P(2)
                                  -4                   1
                                                   2        -5
    nil    1    1     nil   1            5
                                               6
                                                       4       nil      1     1     2     1
    nil   nil   nil   2     2                                  nil     nil    nil   2     2
p = nil    3    nil   nil   nil                            p = nil      3     nil   2     2
    4      1     4    nil   1                                  4        1      4    nil   1
    nil   nil   nil   5     nil                                nil     nil    nil   5     nil
                                       Proiectarea Algoritmilor 2010
Example (4)
   0      3     8 4         -4                              0          3     8     4     -4
   ∞      0     ∞ 1         7                               ∞          0     ∞     1     7
D= ∞      4     0 5         11                           D= ∞          4     0     5     11
   2      5     -5 0        -2                              2          -1    -5    0     -2
                                               2
   ∞      ∞     ∞ 6         0           3               4   ∞          ∞     ∞     6     0
                                             7 8
                                  1                         3
           D(2), P(2)                                                   D(3), P(3)
                                  -4                   1
                                                   2        -5
    nil    1    1     2     1            5
                                               6
                                                       4       nil      1    1     2     1
    nil   nil   nil   2     2                                  nil     nil   nil   2     2
p = nil    3    nil   2     2                              p = nil      3    nil   2     2
    4      1     4    nil   1                                  4        3     4    nil   1
    nil   nil   nil   5     nil                                nil     nil   nil   5     nil
                                       Proiectarea Algoritmilor 2010
Example (5)
   0      3     8     4     -4                              0           3    -1     4    -4
   ∞      0     ∞     1     7                               3           0    -4     1    -1
D= ∞      4     0     5     11                           D= 7           4    0      5     3
   2      -1    -5    0     -2                              2          -1    -5    0     -2
                                               2
   ∞      ∞     ∞     6     0           3               4   8           5    1     6     0
                                             7 8
                                  1                         3
           D(3), P(3)                                                    D(4), P(4)
                                  -4                   1
                                                   2       -5
    nil    1    1     2     1            5             4      nil       1    4     2     1
                                               6
    nil   nil   nil   2     2                                 4        nil   4     2     1
p = nil    3    nil   2     2                              p= 4         3    nil   2     1
    4      3     4    nil   1                                 4         3    4     nil   1
    nil   nil   nil   5     nil                               4         3    4     5     nil
                                       Proiectarea Algoritmilor 2010
Example (6)
   0      3    -1     4    -4                              0           1    -3     2    -4
   3      0    -4     1    -1                              3           0    -4     1    -1
D= 7      4    0      5     3                           D= 7           4    0      5     3
   2     -1    -5    0     -2                              2          -1    -5    0     -2
                                              2
   8      5    1     6     0           3               4   8           5    1     6     0
                                            7 8
          D(4), P(4)             1                         3            D(5), P(5)
                                 -4                   1
                                                  2       -5
   nil    1    4     2     1            5             4      nil       3    4     5     1
                                              6
   4     nil   4     2     1                                 4        nil   4     2     1
p= 4      3    nil   2     1                              p= 4         3    nil   2     1
   4      3    4     nil   1                                 4         3    4     nil   1
   4      3    4     5     nil                               4         3    4     5     nil
                                      Proiectarea Algoritmilor 2010
Johnson’s Algorithm
   We want to find an algorithm that works better than
    F-W for sparse graphs
   Use SSSP algorithms
       No negative edges: use Dijkstra – n times  (n2*logn)
       Problem if we have negative weight edges  cannot use
        Dijkstra  B-F – n times is not good enough  (n3)
   Therefore, we want to find an (n2*logn) algorithm
    that works on both positive and negative weight
    edges!

   Combines Bellman-Ford and Dijkstra
Johnson’s Algorithm – Idea
   We would like:
       To transform any negative-weighted graph into a graph
        with positive weights
       Such that the minimum path using the new weights is the
        same path for the original weights

   (G, W) => (G, W1)
       w(u, v) can be negative
       w1(u, v) >= 0 for all (u, v)
       p is a minimum path u..v in (G, W) => p is also a minimum
        path u..v in (G, W1)
How to Compute W1?
   Computing W1 is not so simple
   Simplistic idea:
       Find the minimum negative weight edge
       Add the absolute value of that weight to all the other
        weights in the graph
       Then, these new weights are always >= 0
                   3    b                              10   b
               a              8                    a            15
               5                                  12
                                  c                              c
                   d     -7                            d    0

                       Look at w(abd) in the two graphs
                             This idea does not work!
How to Compute W1? Use B-F
   New idea: build a new graph G’(V’, E’)
       V’ = V U {s}
       E’ = E U {(s, v) for all vV}
       w’(s, v) = 0 for all vV
       w’(u, v) = w(u, v) for all u,vV
   Run Bellman-Ford on G’ from s
       The result is h(v)= δ(s, v) in G’ for all vV
       h(v) may be positive or negative
       We can also detect the negative cycles in G’
   The new weight function for G is:
       w1(u, v) = w(u, v) + h(u) – h(v) >= 0 for all (u, v)E
Properties of G’ and W1
   For any path p = <v0, v1, …, vk> in G:
       w1(p) = w(p) + h(v0) – h(vk)


   The negative weight cycles in G’ are the same as the
    negative weight cycles in G. Why?
       Because the weight of all the cycles is the same for w1 as for w
       Cycle p => v0 = vk => w1(p) = w(p)


   Prove that w1(u, v) = w(u, v) + h(u) – h(v) >= 0 for all (u,
    v)E
       Use triangle inequality for edge (u, v)E
       In G’, we have h(v) = δ(s, v) <= h(u) + w(u, v) = δ(s, u) + w(u, v)
       Therefore h(u) + w(u, v) – h(v) >= 0
Johnson’s Algorithm – Pseudocode
JOHNSON(G, W)
  G’ = (V’,E’);
  V’ = V  {s};                                               // add new source s
  E’ = E  (s,u), uV; w’(s,u) = 0;
  IF (BF(G’, W’) == FALSE)                       // run BF on G’
      PRINT “Error! Negative cycle was found!”
  ELSE
      FOREACH (vV)
          h(v) = δ(s,v);                                      // computed by Bellman Ford
      FOREACH ((u,v)E)
          w1(u,v) = w(u,v) + h(u) - h(v)                      // compute new positive weights
      FOREACH (uV)
          Dijkstra(G,w1,u)          // run Dijkstra for each vertex as a source using w1
          FOREACH (vV)
              d(u,v) = δ1(u,v) + h(v) - h(u)     // we need to switch back from w1 to w


Time complexity: (n*m + n2*logn)  (n2 * logn) for sparse graphs
Example (1)


                                                                        0       -1
              2                                                 0               2
      3                   4                                         3                       4
          7                                0              0                 7
                                                    0                           8                        -5
              8                                s          1                                          3
 1                             3
                      1                                                                 1
                  2                                 0      -4                       2
 -4                           -5                                                                    -5
      5               4                                              5                  4
              6                                           0                     6               0
                                   Add s and run                    -4
                                    B-F on the
                                    new graph.




                                        Proiectarea Algoritmilor 2010
Example (2)
                           0       -1
                   0               2
                       3                       4
0            0                 7
        0                          8                            -5
    s        1                                          3
                                                                                     5     -1
                                           1
        0     -4                       2                                     1
                                                       -5                                  2
                        5                  4                                     4                     0
             0                     6               0        0            0            10
                       -4                                            0                     13                      -5
                                                                s        1                                     3
                                                                                                   0
                                                                     4   0                     2
                                                                                                               0

            w1(u,v) = w(u,v) + h(u) - h(v)                                        5                4
                                                                         0                 2               0
                                                                                 -4

                                                       Proiectarea Algoritmilor 2010
Example (3)
                        5     -1
                                                                              2/1
                1             2
                                                                               2
                    4                     0
0           0                                                      4                      0
                         10                           -5     0/0                              2/-3
        0                     13                                       10
    s       1                                     3                           13
                                                             1                                 3
                                      0
        4   0                     2                                                   0
                                                  0           0                   2
                                                                                              0
                     5                4
            0                 2               0                     5                  4
                    -4                                                        2
                                                                   0/-4               2/2
                                              Remove s

                         Run Dijkstra from each vertex => (δ1(u, v)).
                         Recompute the distances:
                                 d(u,v) = δ1(u,v) + h(v) - h(u)

                                              Proiectarea Algoritmilor 2010
Example (4)
                       0/0                                                                           0/4
                        2                                                                             2
          4                         0                                                   4                         0
2/3           10                            0/-4                              2/7           10                            0/0
                       13                                                                            13
 1                                           3                                 1                                           3
                                0                                                                     2       0
 0
                        2
                                            0
                                                    0    1   -3     2    -4     0                                         0
           5                    4                   3    0   -4     1    -1              5                    4
                   2                                                                             2
          2/-1                  0/1                 7    4   0      5     3             2/3                   0/5
                        0/-1                        2   -1   -5    0     -2                           2/5
                         2                                                                             2
              4                         0           8    5   1     6     0                  4                         0
 2/2              10                            0/-5                           4/8              10                            2/1
                         13                                                                            13
  1                                              3                              1                                              3
                            2       0                                                                     2       0
      0                                         0                                   0                                         0
            5                       4                                                     5                       4
                        2                                                                             2
           2/-2                     0/0                                                  0/0                      2/6
                                                         Proiectarea Algoritmilor 2010
Application: Transitive Closure
   Given a graph G(V, E)
   Compute the transitive closure of G: G*(V, E*)
   E* = {(u, v) | there exists at least a path in G from u
    to v, u..v}
   G* is an unweighted graph  we only need to
    compute E* or the adjacency matrix of G*

   We can use different algorithms
   One algorithm is an adapted version of Floyd-
    Warshall
       Initialize A(0)[i, j] = 1 if (i, j)E and A(0)[i, j] = 0 o/w
       A(k)[i, j] = A(k-1)[i, j] OR (A(k-1)[i, k] AND A(k-1)[k, j])
Transitive Closure – Pseudocode
TRANSITIVE-CLOSURE(G, W)
  n = |V[G]|
  FOR (i = 1; i <= n; i++)
          FOR (j = 1; j <= n; j++)
                       IF (W[i][j] != INF)
                                     A[0][i][j] = 1
                       ELSE
                                     A[0][i][j] = 0
  FOR (k = 1; k <= n; k++)
          FOR (i = 1; i <= n; i++)
                       FOR (j = 1; j <= n; j++)
                                     A[k][i][j] = A[k-1][i][j] OR (A[k-1][i][k] AND A[k-1][k][j])
  RETURN A[n]
Conclusions
   We can use SSSP algorithms for computing APSP

   But there are better solutions specific to the APSP
    problem!

   Floyd-Warshall for dense graphs: (n3)
   Johnson for sparse graphs: (n2 * logn)
References
   CLRS – Chapter 25

   R. Sedgewick, K Wayne – Algorithms and Data
    Structures – Princeton 2007
    www.cs.princeton.edu/~rs/AlgsDS07/
       Problem 1 and the corresponding images are taken from these
        slides!


   MIT OCW – Introduction to Algorithms – video lecture 19

Contenu connexe

Tendances

Estimating structured vector autoregressive models
Estimating structured vector autoregressive modelsEstimating structured vector autoregressive models
Estimating structured vector autoregressive modelsAkira Tanimoto
 
Boundedness of the Twisted Paraproduct
Boundedness of the Twisted ParaproductBoundedness of the Twisted Paraproduct
Boundedness of the Twisted ParaproductVjekoslavKovac1
 
5.3 dynamic programming
5.3 dynamic programming5.3 dynamic programming
5.3 dynamic programmingKrish_ver2
 
Ece formula sheet
Ece formula sheetEce formula sheet
Ece formula sheetManasa Mona
 
String Matching with Finite Automata and Knuth Morris Pratt Algorithm
String Matching with Finite Automata and Knuth Morris Pratt AlgorithmString Matching with Finite Automata and Knuth Morris Pratt Algorithm
String Matching with Finite Automata and Knuth Morris Pratt AlgorithmKiran K
 
Signals and Systems Formula Sheet
Signals and Systems Formula SheetSignals and Systems Formula Sheet
Signals and Systems Formula SheetHaris Hassan
 
MLP輪読スパース8章 トレースノルム正則化
MLP輪読スパース8章 トレースノルム正則化MLP輪読スパース8章 トレースノルム正則化
MLP輪読スパース8章 トレースノルム正則化Akira Tanimoto
 
On Twisted Paraproducts and some other Multilinear Singular Integrals
On Twisted Paraproducts and some other Multilinear Singular IntegralsOn Twisted Paraproducts and some other Multilinear Singular Integrals
On Twisted Paraproducts and some other Multilinear Singular IntegralsVjekoslavKovac1
 
Linear Combination, Span And Linearly Independent, Dependent Set
Linear Combination, Span And Linearly Independent, Dependent SetLinear Combination, Span And Linearly Independent, Dependent Set
Linear Combination, Span And Linearly Independent, Dependent SetDhaval Shukla
 
Chapter3 - Fourier Series Representation of Periodic Signals
Chapter3 - Fourier Series Representation of Periodic SignalsChapter3 - Fourier Series Representation of Periodic Signals
Chapter3 - Fourier Series Representation of Periodic SignalsAttaporn Ninsuwan
 
Bellman functions and Lp estimates for paraproducts
Bellman functions and Lp estimates for paraproductsBellman functions and Lp estimates for paraproducts
Bellman functions and Lp estimates for paraproductsVjekoslavKovac1
 
Physical Chemistry Assignment Help
Physical Chemistry Assignment HelpPhysical Chemistry Assignment Help
Physical Chemistry Assignment HelpEdu Assignment Help
 
Trilinear embedding for divergence-form operators
Trilinear embedding for divergence-form operatorsTrilinear embedding for divergence-form operators
Trilinear embedding for divergence-form operatorsVjekoslavKovac1
 
Minimum spanning tree algorithms by ibrahim_alfayoumi
Minimum spanning tree algorithms by ibrahim_alfayoumiMinimum spanning tree algorithms by ibrahim_alfayoumi
Minimum spanning tree algorithms by ibrahim_alfayoumiIbrahim Alfayoumi
 
Ecfft zk studyclub 9.9
Ecfft zk studyclub 9.9Ecfft zk studyclub 9.9
Ecfft zk studyclub 9.9Alex Pruden
 
Chapter 9 computation of the dft
Chapter 9 computation of the dftChapter 9 computation of the dft
Chapter 9 computation of the dftmikeproud
 

Tendances (20)

Estimating structured vector autoregressive models
Estimating structured vector autoregressive modelsEstimating structured vector autoregressive models
Estimating structured vector autoregressive models
 
Boundedness of the Twisted Paraproduct
Boundedness of the Twisted ParaproductBoundedness of the Twisted Paraproduct
Boundedness of the Twisted Paraproduct
 
5.3 dynamic programming
5.3 dynamic programming5.3 dynamic programming
5.3 dynamic programming
 
Ece formula sheet
Ece formula sheetEce formula sheet
Ece formula sheet
 
String Matching with Finite Automata and Knuth Morris Pratt Algorithm
String Matching with Finite Automata and Knuth Morris Pratt AlgorithmString Matching with Finite Automata and Knuth Morris Pratt Algorithm
String Matching with Finite Automata and Knuth Morris Pratt Algorithm
 
Signals and Systems Formula Sheet
Signals and Systems Formula SheetSignals and Systems Formula Sheet
Signals and Systems Formula Sheet
 
MLP輪読スパース8章 トレースノルム正則化
MLP輪読スパース8章 トレースノルム正則化MLP輪読スパース8章 トレースノルム正則化
MLP輪読スパース8章 トレースノルム正則化
 
On Twisted Paraproducts and some other Multilinear Singular Integrals
On Twisted Paraproducts and some other Multilinear Singular IntegralsOn Twisted Paraproducts and some other Multilinear Singular Integrals
On Twisted Paraproducts and some other Multilinear Singular Integrals
 
2018 MUMS Fall Course - Bayesian inference for model calibration in UQ - Ralp...
2018 MUMS Fall Course - Bayesian inference for model calibration in UQ - Ralp...2018 MUMS Fall Course - Bayesian inference for model calibration in UQ - Ralp...
2018 MUMS Fall Course - Bayesian inference for model calibration in UQ - Ralp...
 
Linear Combination, Span And Linearly Independent, Dependent Set
Linear Combination, Span And Linearly Independent, Dependent SetLinear Combination, Span And Linearly Independent, Dependent Set
Linear Combination, Span And Linearly Independent, Dependent Set
 
5.1 greedy
5.1 greedy5.1 greedy
5.1 greedy
 
Chapter3 - Fourier Series Representation of Periodic Signals
Chapter3 - Fourier Series Representation of Periodic SignalsChapter3 - Fourier Series Representation of Periodic Signals
Chapter3 - Fourier Series Representation of Periodic Signals
 
Bellman functions and Lp estimates for paraproducts
Bellman functions and Lp estimates for paraproductsBellman functions and Lp estimates for paraproducts
Bellman functions and Lp estimates for paraproducts
 
Physical Chemistry Assignment Help
Physical Chemistry Assignment HelpPhysical Chemistry Assignment Help
Physical Chemistry Assignment Help
 
Shortest Path Problem
Shortest Path ProblemShortest Path Problem
Shortest Path Problem
 
Trilinear embedding for divergence-form operators
Trilinear embedding for divergence-form operatorsTrilinear embedding for divergence-form operators
Trilinear embedding for divergence-form operators
 
5.1 greedy 03
5.1 greedy 035.1 greedy 03
5.1 greedy 03
 
Minimum spanning tree algorithms by ibrahim_alfayoumi
Minimum spanning tree algorithms by ibrahim_alfayoumiMinimum spanning tree algorithms by ibrahim_alfayoumi
Minimum spanning tree algorithms by ibrahim_alfayoumi
 
Ecfft zk studyclub 9.9
Ecfft zk studyclub 9.9Ecfft zk studyclub 9.9
Ecfft zk studyclub 9.9
 
Chapter 9 computation of the dft
Chapter 9 computation of the dftChapter 9 computation of the dft
Chapter 9 computation of the dft
 

Similaire à Algorithm Design and Complexity - Course 11

6-Nfa & equivalence with RE.pdf
6-Nfa & equivalence with RE.pdf6-Nfa & equivalence with RE.pdf
6-Nfa & equivalence with RE.pdfshruti533256
 
Simplified Runtime Analysis of Estimation of Distribution Algorithms
Simplified Runtime Analysis of Estimation of Distribution AlgorithmsSimplified Runtime Analysis of Estimation of Distribution Algorithms
Simplified Runtime Analysis of Estimation of Distribution AlgorithmsPK Lehre
 
Simplified Runtime Analysis of Estimation of Distribution Algorithms
Simplified Runtime Analysis of Estimation of Distribution AlgorithmsSimplified Runtime Analysis of Estimation of Distribution Algorithms
Simplified Runtime Analysis of Estimation of Distribution AlgorithmsPer Kristian Lehre
 
Lp and ip programming cp 9
Lp and ip programming cp 9Lp and ip programming cp 9
Lp and ip programming cp 9M S Prasad
 
A Note on Latent LSTM Allocation
A Note on Latent LSTM AllocationA Note on Latent LSTM Allocation
A Note on Latent LSTM AllocationTomonari Masada
 
Linear Cryptanalysis Lecture 線形解読法
Linear Cryptanalysis Lecture 線形解読法Linear Cryptanalysis Lecture 線形解読法
Linear Cryptanalysis Lecture 線形解読法Kai Katsumata
 
Topic modeling with Poisson factorization (2)
Topic modeling with Poisson factorization (2)Topic modeling with Poisson factorization (2)
Topic modeling with Poisson factorization (2)Tomonari Masada
 
Graph for Coulomb damped oscillation
Graph for Coulomb damped oscillationGraph for Coulomb damped oscillation
Graph for Coulomb damped oscillationphanhung20
 
Double Robustness: Theory and Applications with Missing Data
Double Robustness: Theory and Applications with Missing DataDouble Robustness: Theory and Applications with Missing Data
Double Robustness: Theory and Applications with Missing DataLu Mao
 

Similaire à Algorithm Design and Complexity - Course 11 (20)

6-Nfa & equivalence with RE.pdf
6-Nfa & equivalence with RE.pdf6-Nfa & equivalence with RE.pdf
6-Nfa & equivalence with RE.pdf
 
Unit 3 daa
Unit 3 daaUnit 3 daa
Unit 3 daa
 
Simplified Runtime Analysis of Estimation of Distribution Algorithms
Simplified Runtime Analysis of Estimation of Distribution AlgorithmsSimplified Runtime Analysis of Estimation of Distribution Algorithms
Simplified Runtime Analysis of Estimation of Distribution Algorithms
 
Simplified Runtime Analysis of Estimation of Distribution Algorithms
Simplified Runtime Analysis of Estimation of Distribution AlgorithmsSimplified Runtime Analysis of Estimation of Distribution Algorithms
Simplified Runtime Analysis of Estimation of Distribution Algorithms
 
algorithm Unit 3
algorithm Unit 3algorithm Unit 3
algorithm Unit 3
 
2018 MUMS Fall Course - Statistical Representation of Model Input (EDITED) - ...
2018 MUMS Fall Course - Statistical Representation of Model Input (EDITED) - ...2018 MUMS Fall Course - Statistical Representation of Model Input (EDITED) - ...
2018 MUMS Fall Course - Statistical Representation of Model Input (EDITED) - ...
 
lecture6.ppt
lecture6.pptlecture6.ppt
lecture6.ppt
 
Lp and ip programming cp 9
Lp and ip programming cp 9Lp and ip programming cp 9
Lp and ip programming cp 9
 
Number theory lecture (part 1)
Number theory lecture (part 1)Number theory lecture (part 1)
Number theory lecture (part 1)
 
A Note on Latent LSTM Allocation
A Note on Latent LSTM AllocationA Note on Latent LSTM Allocation
A Note on Latent LSTM Allocation
 
Sequences
SequencesSequences
Sequences
 
Linear Cryptanalysis Lecture 線形解読法
Linear Cryptanalysis Lecture 線形解読法Linear Cryptanalysis Lecture 線形解読法
Linear Cryptanalysis Lecture 線形解読法
 
NODDEA2012_VANKOVA
NODDEA2012_VANKOVANODDEA2012_VANKOVA
NODDEA2012_VANKOVA
 
Disjoint sets
Disjoint setsDisjoint sets
Disjoint sets
 
Topic modeling with Poisson factorization (2)
Topic modeling with Poisson factorization (2)Topic modeling with Poisson factorization (2)
Topic modeling with Poisson factorization (2)
 
Graph for Coulomb damped oscillation
Graph for Coulomb damped oscillationGraph for Coulomb damped oscillation
Graph for Coulomb damped oscillation
 
Double Robustness: Theory and Applications with Missing Data
Double Robustness: Theory and Applications with Missing DataDouble Robustness: Theory and Applications with Missing Data
Double Robustness: Theory and Applications with Missing Data
 
Unit 3
Unit 3Unit 3
Unit 3
 
Unit 3
Unit 3Unit 3
Unit 3
 
Dsp lecture vol 2 dft & fft
Dsp lecture vol 2 dft & fftDsp lecture vol 2 dft & fft
Dsp lecture vol 2 dft & fft
 

Plus de Traian Rebedea

An Evolution of Deep Learning Models for AI2 Reasoning Challenge
An Evolution of Deep Learning Models for AI2 Reasoning ChallengeAn Evolution of Deep Learning Models for AI2 Reasoning Challenge
An Evolution of Deep Learning Models for AI2 Reasoning ChallengeTraian Rebedea
 
AI @ Wholi - Bucharest.AI Meetup #5
AI @ Wholi - Bucharest.AI Meetup #5AI @ Wholi - Bucharest.AI Meetup #5
AI @ Wholi - Bucharest.AI Meetup #5Traian Rebedea
 
Deep neural networks for matching online social networking profiles
Deep neural networks for matching online social networking profilesDeep neural networks for matching online social networking profiles
Deep neural networks for matching online social networking profilesTraian Rebedea
 
Intro to Deep Learning for Question Answering
Intro to Deep Learning for Question AnsweringIntro to Deep Learning for Question Answering
Intro to Deep Learning for Question AnsweringTraian Rebedea
 
How useful are semantic links for the detection of implicit references in csc...
How useful are semantic links for the detection of implicit references in csc...How useful are semantic links for the detection of implicit references in csc...
How useful are semantic links for the detection of implicit references in csc...Traian Rebedea
 
A focused crawler for romanian words discovery
A focused crawler for romanian words discoveryA focused crawler for romanian words discovery
A focused crawler for romanian words discoveryTraian Rebedea
 
Detecting and Describing Historical Periods in a Large Corpora
Detecting and Describing Historical Periods in a Large CorporaDetecting and Describing Historical Periods in a Large Corpora
Detecting and Describing Historical Periods in a Large CorporaTraian Rebedea
 
Practical machine learning - Part 1
Practical machine learning - Part 1Practical machine learning - Part 1
Practical machine learning - Part 1Traian Rebedea
 
Propunere de dezvoltare a carierei universitare
Propunere de dezvoltare a carierei universitarePropunere de dezvoltare a carierei universitare
Propunere de dezvoltare a carierei universitareTraian Rebedea
 
Automatic plagiarism detection system for specialized corpora
Automatic plagiarism detection system for specialized corporaAutomatic plagiarism detection system for specialized corpora
Automatic plagiarism detection system for specialized corporaTraian Rebedea
 
Relevance based ranking of video comments on YouTube
Relevance based ranking of video comments on YouTubeRelevance based ranking of video comments on YouTube
Relevance based ranking of video comments on YouTubeTraian Rebedea
 
Opinion mining for social media and news items in Romanian
Opinion mining for social media and news items in RomanianOpinion mining for social media and news items in Romanian
Opinion mining for social media and news items in RomanianTraian Rebedea
 
PhD Defense: Computer-Based Support and Feedback for Collaborative Chat Conve...
PhD Defense: Computer-Based Support and Feedback for Collaborative Chat Conve...PhD Defense: Computer-Based Support and Feedback for Collaborative Chat Conve...
PhD Defense: Computer-Based Support and Feedback for Collaborative Chat Conve...Traian Rebedea
 
Importanța algoritmilor pentru problemele de la interviuri
Importanța algoritmilor pentru problemele de la interviuriImportanța algoritmilor pentru problemele de la interviuri
Importanța algoritmilor pentru problemele de la interviuriTraian Rebedea
 
Web services for supporting the interactions of learners in the social web - ...
Web services for supporting the interactions of learners in the social web - ...Web services for supporting the interactions of learners in the social web - ...
Web services for supporting the interactions of learners in the social web - ...Traian Rebedea
 
Automatic assessment of collaborative chat conversations with PolyCAFe - EC-T...
Automatic assessment of collaborative chat conversations with PolyCAFe - EC-T...Automatic assessment of collaborative chat conversations with PolyCAFe - EC-T...
Automatic assessment of collaborative chat conversations with PolyCAFe - EC-T...Traian Rebedea
 
Conclusions and Recommendations of the Romanian ICT RTD Survey
Conclusions and Recommendations of the Romanian ICT RTD SurveyConclusions and Recommendations of the Romanian ICT RTD Survey
Conclusions and Recommendations of the Romanian ICT RTD SurveyTraian Rebedea
 
Istoria Web-ului - part 2 - tentativ How to Web 2009
Istoria Web-ului - part 2 - tentativ How to Web 2009Istoria Web-ului - part 2 - tentativ How to Web 2009
Istoria Web-ului - part 2 - tentativ How to Web 2009Traian Rebedea
 
Istoria Web-ului - part 1 (2) - tentativ How to Web 2009
Istoria Web-ului - part 1 (2) - tentativ How to Web 2009Istoria Web-ului - part 1 (2) - tentativ How to Web 2009
Istoria Web-ului - part 1 (2) - tentativ How to Web 2009Traian Rebedea
 

Plus de Traian Rebedea (20)

An Evolution of Deep Learning Models for AI2 Reasoning Challenge
An Evolution of Deep Learning Models for AI2 Reasoning ChallengeAn Evolution of Deep Learning Models for AI2 Reasoning Challenge
An Evolution of Deep Learning Models for AI2 Reasoning Challenge
 
AI @ Wholi - Bucharest.AI Meetup #5
AI @ Wholi - Bucharest.AI Meetup #5AI @ Wholi - Bucharest.AI Meetup #5
AI @ Wholi - Bucharest.AI Meetup #5
 
Deep neural networks for matching online social networking profiles
Deep neural networks for matching online social networking profilesDeep neural networks for matching online social networking profiles
Deep neural networks for matching online social networking profiles
 
Intro to Deep Learning for Question Answering
Intro to Deep Learning for Question AnsweringIntro to Deep Learning for Question Answering
Intro to Deep Learning for Question Answering
 
What is word2vec?
What is word2vec?What is word2vec?
What is word2vec?
 
How useful are semantic links for the detection of implicit references in csc...
How useful are semantic links for the detection of implicit references in csc...How useful are semantic links for the detection of implicit references in csc...
How useful are semantic links for the detection of implicit references in csc...
 
A focused crawler for romanian words discovery
A focused crawler for romanian words discoveryA focused crawler for romanian words discovery
A focused crawler for romanian words discovery
 
Detecting and Describing Historical Periods in a Large Corpora
Detecting and Describing Historical Periods in a Large CorporaDetecting and Describing Historical Periods in a Large Corpora
Detecting and Describing Historical Periods in a Large Corpora
 
Practical machine learning - Part 1
Practical machine learning - Part 1Practical machine learning - Part 1
Practical machine learning - Part 1
 
Propunere de dezvoltare a carierei universitare
Propunere de dezvoltare a carierei universitarePropunere de dezvoltare a carierei universitare
Propunere de dezvoltare a carierei universitare
 
Automatic plagiarism detection system for specialized corpora
Automatic plagiarism detection system for specialized corporaAutomatic plagiarism detection system for specialized corpora
Automatic plagiarism detection system for specialized corpora
 
Relevance based ranking of video comments on YouTube
Relevance based ranking of video comments on YouTubeRelevance based ranking of video comments on YouTube
Relevance based ranking of video comments on YouTube
 
Opinion mining for social media and news items in Romanian
Opinion mining for social media and news items in RomanianOpinion mining for social media and news items in Romanian
Opinion mining for social media and news items in Romanian
 
PhD Defense: Computer-Based Support and Feedback for Collaborative Chat Conve...
PhD Defense: Computer-Based Support and Feedback for Collaborative Chat Conve...PhD Defense: Computer-Based Support and Feedback for Collaborative Chat Conve...
PhD Defense: Computer-Based Support and Feedback for Collaborative Chat Conve...
 
Importanța algoritmilor pentru problemele de la interviuri
Importanța algoritmilor pentru problemele de la interviuriImportanța algoritmilor pentru problemele de la interviuri
Importanța algoritmilor pentru problemele de la interviuri
 
Web services for supporting the interactions of learners in the social web - ...
Web services for supporting the interactions of learners in the social web - ...Web services for supporting the interactions of learners in the social web - ...
Web services for supporting the interactions of learners in the social web - ...
 
Automatic assessment of collaborative chat conversations with PolyCAFe - EC-T...
Automatic assessment of collaborative chat conversations with PolyCAFe - EC-T...Automatic assessment of collaborative chat conversations with PolyCAFe - EC-T...
Automatic assessment of collaborative chat conversations with PolyCAFe - EC-T...
 
Conclusions and Recommendations of the Romanian ICT RTD Survey
Conclusions and Recommendations of the Romanian ICT RTD SurveyConclusions and Recommendations of the Romanian ICT RTD Survey
Conclusions and Recommendations of the Romanian ICT RTD Survey
 
Istoria Web-ului - part 2 - tentativ How to Web 2009
Istoria Web-ului - part 2 - tentativ How to Web 2009Istoria Web-ului - part 2 - tentativ How to Web 2009
Istoria Web-ului - part 2 - tentativ How to Web 2009
 
Istoria Web-ului - part 1 (2) - tentativ How to Web 2009
Istoria Web-ului - part 1 (2) - tentativ How to Web 2009Istoria Web-ului - part 1 (2) - tentativ How to Web 2009
Istoria Web-ului - part 1 (2) - tentativ How to Web 2009
 

Dernier

Active Learning Strategies (in short ALS).pdf
Active Learning Strategies (in short ALS).pdfActive Learning Strategies (in short ALS).pdf
Active Learning Strategies (in short ALS).pdfPatidar M
 
Blowin' in the Wind of Caste_ Bob Dylan's Song as a Catalyst for Social Justi...
Blowin' in the Wind of Caste_ Bob Dylan's Song as a Catalyst for Social Justi...Blowin' in the Wind of Caste_ Bob Dylan's Song as a Catalyst for Social Justi...
Blowin' in the Wind of Caste_ Bob Dylan's Song as a Catalyst for Social Justi...DhatriParmar
 
How to Make a Duplicate of Your Odoo 17 Database
How to Make a Duplicate of Your Odoo 17 DatabaseHow to Make a Duplicate of Your Odoo 17 Database
How to Make a Duplicate of Your Odoo 17 DatabaseCeline George
 
Indexing Structures in Database Management system.pdf
Indexing Structures in Database Management system.pdfIndexing Structures in Database Management system.pdf
Indexing Structures in Database Management system.pdfChristalin Nelson
 
ARTERIAL BLOOD GAS ANALYSIS........pptx
ARTERIAL BLOOD  GAS ANALYSIS........pptxARTERIAL BLOOD  GAS ANALYSIS........pptx
ARTERIAL BLOOD GAS ANALYSIS........pptxAneriPatwari
 
Decoding the Tweet _ Practical Criticism in the Age of Hashtag.pptx
Decoding the Tweet _ Practical Criticism in the Age of Hashtag.pptxDecoding the Tweet _ Practical Criticism in the Age of Hashtag.pptx
Decoding the Tweet _ Practical Criticism in the Age of Hashtag.pptxDhatriParmar
 
Narcotic and Non Narcotic Analgesic..pdf
Narcotic and Non Narcotic Analgesic..pdfNarcotic and Non Narcotic Analgesic..pdf
Narcotic and Non Narcotic Analgesic..pdfPrerana Jadhav
 
Q-Factor HISPOL Quiz-6th April 2024, Quiz Club NITW
Q-Factor HISPOL Quiz-6th April 2024, Quiz Club NITWQ-Factor HISPOL Quiz-6th April 2024, Quiz Club NITW
Q-Factor HISPOL Quiz-6th April 2024, Quiz Club NITWQuiz Club NITW
 
BIOCHEMISTRY-CARBOHYDRATE METABOLISM CHAPTER 2.pptx
BIOCHEMISTRY-CARBOHYDRATE METABOLISM CHAPTER 2.pptxBIOCHEMISTRY-CARBOHYDRATE METABOLISM CHAPTER 2.pptx
BIOCHEMISTRY-CARBOHYDRATE METABOLISM CHAPTER 2.pptxSayali Powar
 
Oppenheimer Film Discussion for Philosophy and Film
Oppenheimer Film Discussion for Philosophy and FilmOppenheimer Film Discussion for Philosophy and Film
Oppenheimer Film Discussion for Philosophy and FilmStan Meyer
 
MS4 level being good citizen -imperative- (1) (1).pdf
MS4 level   being good citizen -imperative- (1) (1).pdfMS4 level   being good citizen -imperative- (1) (1).pdf
MS4 level being good citizen -imperative- (1) (1).pdfMr Bounab Samir
 
How to Manage Buy 3 Get 1 Free in Odoo 17
How to Manage Buy 3 Get 1 Free in Odoo 17How to Manage Buy 3 Get 1 Free in Odoo 17
How to Manage Buy 3 Get 1 Free in Odoo 17Celine George
 
Sulphonamides, mechanisms and their uses
Sulphonamides, mechanisms and their usesSulphonamides, mechanisms and their uses
Sulphonamides, mechanisms and their usesVijayaLaxmi84
 
Grade Three -ELLNA-REVIEWER-ENGLISH.pptx
Grade Three -ELLNA-REVIEWER-ENGLISH.pptxGrade Three -ELLNA-REVIEWER-ENGLISH.pptx
Grade Three -ELLNA-REVIEWER-ENGLISH.pptxkarenfajardo43
 
4.9.24 School Desegregation in Boston.pptx
4.9.24 School Desegregation in Boston.pptx4.9.24 School Desegregation in Boston.pptx
4.9.24 School Desegregation in Boston.pptxmary850239
 
Mythology Quiz-4th April 2024, Quiz Club NITW
Mythology Quiz-4th April 2024, Quiz Club NITWMythology Quiz-4th April 2024, Quiz Club NITW
Mythology Quiz-4th April 2024, Quiz Club NITWQuiz Club NITW
 
4.16.24 Poverty and Precarity--Desmond.pptx
4.16.24 Poverty and Precarity--Desmond.pptx4.16.24 Poverty and Precarity--Desmond.pptx
4.16.24 Poverty and Precarity--Desmond.pptxmary850239
 
ICS2208 Lecture6 Notes for SL spaces.pdf
ICS2208 Lecture6 Notes for SL spaces.pdfICS2208 Lecture6 Notes for SL spaces.pdf
ICS2208 Lecture6 Notes for SL spaces.pdfVanessa Camilleri
 
Beauty Amidst the Bytes_ Unearthing Unexpected Advantages of the Digital Wast...
Beauty Amidst the Bytes_ Unearthing Unexpected Advantages of the Digital Wast...Beauty Amidst the Bytes_ Unearthing Unexpected Advantages of the Digital Wast...
Beauty Amidst the Bytes_ Unearthing Unexpected Advantages of the Digital Wast...DhatriParmar
 

Dernier (20)

Active Learning Strategies (in short ALS).pdf
Active Learning Strategies (in short ALS).pdfActive Learning Strategies (in short ALS).pdf
Active Learning Strategies (in short ALS).pdf
 
Blowin' in the Wind of Caste_ Bob Dylan's Song as a Catalyst for Social Justi...
Blowin' in the Wind of Caste_ Bob Dylan's Song as a Catalyst for Social Justi...Blowin' in the Wind of Caste_ Bob Dylan's Song as a Catalyst for Social Justi...
Blowin' in the Wind of Caste_ Bob Dylan's Song as a Catalyst for Social Justi...
 
How to Make a Duplicate of Your Odoo 17 Database
How to Make a Duplicate of Your Odoo 17 DatabaseHow to Make a Duplicate of Your Odoo 17 Database
How to Make a Duplicate of Your Odoo 17 Database
 
Indexing Structures in Database Management system.pdf
Indexing Structures in Database Management system.pdfIndexing Structures in Database Management system.pdf
Indexing Structures in Database Management system.pdf
 
ARTERIAL BLOOD GAS ANALYSIS........pptx
ARTERIAL BLOOD  GAS ANALYSIS........pptxARTERIAL BLOOD  GAS ANALYSIS........pptx
ARTERIAL BLOOD GAS ANALYSIS........pptx
 
Decoding the Tweet _ Practical Criticism in the Age of Hashtag.pptx
Decoding the Tweet _ Practical Criticism in the Age of Hashtag.pptxDecoding the Tweet _ Practical Criticism in the Age of Hashtag.pptx
Decoding the Tweet _ Practical Criticism in the Age of Hashtag.pptx
 
Faculty Profile prashantha K EEE dept Sri Sairam college of Engineering
Faculty Profile prashantha K EEE dept Sri Sairam college of EngineeringFaculty Profile prashantha K EEE dept Sri Sairam college of Engineering
Faculty Profile prashantha K EEE dept Sri Sairam college of Engineering
 
Narcotic and Non Narcotic Analgesic..pdf
Narcotic and Non Narcotic Analgesic..pdfNarcotic and Non Narcotic Analgesic..pdf
Narcotic and Non Narcotic Analgesic..pdf
 
Q-Factor HISPOL Quiz-6th April 2024, Quiz Club NITW
Q-Factor HISPOL Quiz-6th April 2024, Quiz Club NITWQ-Factor HISPOL Quiz-6th April 2024, Quiz Club NITW
Q-Factor HISPOL Quiz-6th April 2024, Quiz Club NITW
 
BIOCHEMISTRY-CARBOHYDRATE METABOLISM CHAPTER 2.pptx
BIOCHEMISTRY-CARBOHYDRATE METABOLISM CHAPTER 2.pptxBIOCHEMISTRY-CARBOHYDRATE METABOLISM CHAPTER 2.pptx
BIOCHEMISTRY-CARBOHYDRATE METABOLISM CHAPTER 2.pptx
 
Oppenheimer Film Discussion for Philosophy and Film
Oppenheimer Film Discussion for Philosophy and FilmOppenheimer Film Discussion for Philosophy and Film
Oppenheimer Film Discussion for Philosophy and Film
 
MS4 level being good citizen -imperative- (1) (1).pdf
MS4 level   being good citizen -imperative- (1) (1).pdfMS4 level   being good citizen -imperative- (1) (1).pdf
MS4 level being good citizen -imperative- (1) (1).pdf
 
How to Manage Buy 3 Get 1 Free in Odoo 17
How to Manage Buy 3 Get 1 Free in Odoo 17How to Manage Buy 3 Get 1 Free in Odoo 17
How to Manage Buy 3 Get 1 Free in Odoo 17
 
Sulphonamides, mechanisms and their uses
Sulphonamides, mechanisms and their usesSulphonamides, mechanisms and their uses
Sulphonamides, mechanisms and their uses
 
Grade Three -ELLNA-REVIEWER-ENGLISH.pptx
Grade Three -ELLNA-REVIEWER-ENGLISH.pptxGrade Three -ELLNA-REVIEWER-ENGLISH.pptx
Grade Three -ELLNA-REVIEWER-ENGLISH.pptx
 
4.9.24 School Desegregation in Boston.pptx
4.9.24 School Desegregation in Boston.pptx4.9.24 School Desegregation in Boston.pptx
4.9.24 School Desegregation in Boston.pptx
 
Mythology Quiz-4th April 2024, Quiz Club NITW
Mythology Quiz-4th April 2024, Quiz Club NITWMythology Quiz-4th April 2024, Quiz Club NITW
Mythology Quiz-4th April 2024, Quiz Club NITW
 
4.16.24 Poverty and Precarity--Desmond.pptx
4.16.24 Poverty and Precarity--Desmond.pptx4.16.24 Poverty and Precarity--Desmond.pptx
4.16.24 Poverty and Precarity--Desmond.pptx
 
ICS2208 Lecture6 Notes for SL spaces.pdf
ICS2208 Lecture6 Notes for SL spaces.pdfICS2208 Lecture6 Notes for SL spaces.pdf
ICS2208 Lecture6 Notes for SL spaces.pdf
 
Beauty Amidst the Bytes_ Unearthing Unexpected Advantages of the Digital Wast...
Beauty Amidst the Bytes_ Unearthing Unexpected Advantages of the Digital Wast...Beauty Amidst the Bytes_ Unearthing Unexpected Advantages of the Digital Wast...
Beauty Amidst the Bytes_ Unearthing Unexpected Advantages of the Digital Wast...
 

Algorithm Design and Complexity - Course 11

  • 1. Algorithm Design and Complexity Course 11
  • 2. Overview  All-Pairs Shortest Paths (APSP)  Using SSSP Algorithms  Simple DP Algorithms  Floyd-Warshall Algorithm  Johnson’s Algorithm  Transitive Closure of a Graph
  • 3. All-Pairs Shortest Paths (APSP)  G(V, E) (un)directed, connected and weighted graph  The weight (cost) function w: E → R  w(u, v) = the weight of the edge (u, v)  Adjacency matrix of weights  W = [w(i, j)] ; 1 <= i, j <= n  w(i, j) = 0 if i = j  w(i, j) = INF if i != j and (i, j)E  w(i, j) = weight of the edge (i, j) if i != j and (i, j)E  Compute the shortest paths between any two vertices in the graph  Use a matrix D = [d(i, j)] ; 1 <= i, j <= n  We want d(i, j) = δ(i, j) = weight of the shortest path from i to j
  • 4. APSP – Predecessors  We also compute a matrix of predecessors  P = [p(i, j)] ; 1 <= i, j <= n  p(i, j) is the predecessor of j on the shortest path i..j  p(i, j) = NIL if there isn’t any path between i and j  Therefore to find out the vertices on the shortest path between any two vertices, u and v, u..v:  1. Start from v’ = v  2. Go to v’ = p(u, v’)  3. If (v’ == u) then stop  4. Else go to step 2  (p(u,v), v), (p(u, p(u,v)), p(u,v))… (u, p(u, … p(u,v)))
  • 5. Solutions for APSP 1. Use SSSP algorithms called n times  Considering each vertex as a source 2. Use specialized algorithms  Try to compute the matrices D and P directly  There is no algorithm that works best for all cases  Consider the best choice given the problem needed to be solved  Dense vs. sparse graph, negative vs. positive weights  Special cases: DAGs  Etc.
  • 6. Using SSSP Algorithms for APSP  For any type of graph  Use Bellman-Ford – n times  n * (n*m) = (n2*m)  Dense graphs: (n4)  Sparse graphs: (n3)  We want to improve it!  Using Dijkstra – n times  Only for positive weighted edges  Fibonacci heaps: n * (n*logn + m) = (n2*logn + n*m)  Dense graphs: (n3)  Sparse graphs: (n2*logn)  Otherwise, choose between binary heap and arrays for the best solution depending on the graph
  • 7. Specific APSP Algorithms  The specific APSP algorithms, should work better than the previous solutions  We want (n3) for any kind of graph  Floyd-Warshall algorithm  Maybe find improvements for specific types of graphs  (n2*logn) for sparse graphs with negative weights  Johnson’s algorithm  For some graphs, the SSSP solutions is the best one  E.g. for DAGS, the SSSP algorithm works great with minor improvements  Use dynamic programming for designing these algorithms
  • 8. APSP DP Algorithms  Use the property: any subpath of a shortest path is also a shortest path!  What kind of sub-problems? 1. Determine the shortest paths that contain at most k edges! (Simple DP algorithms) 2. Determine the shortest paths that contain only the first k vertices as intermediate vertices on the SP (Floyd-Warshall algorithm)  Start with k = 0 and then increase it!
  • 9. Simple DP algorithms  Compute the APSP that contain at most k edges on the determined SP!  Use L(k)[i, j] = the weight of the SP from vertex i to vertex j that contains <= k edges  Start with k = 0 (stop condition for the recursion)  L(0)[i, j] = 0 if i = j  L(0)[i, j] = INF if i != j  Use the following recursion for k >= 1  L(k)[i, j] = min(L(k-1)[i, j] , mink=1..n(L(k-1)[i, k] + w(k, j))) = mink=1..n(L(k-1)[i, k] + w(k, j)) because w(j, j) = 0
  • 10. Simple DP Algorithm for APSP  Can also compute the predecessor matrix as well  Exercise: how to compute it!  Verify the recursive formula when k = 1  L(1)[i, j] should be w(i, j)  But L(1)[i, j] = mink=1..n(L(0)[i, k] + w(k, j)) = L(0)[i, i] + w(i, j) (the only non-INF value) = w(i, j)
  • 11. Simple DP Algorithm for APSP (2)  There are at most n – 1 edges on each shortest path  Therefore, we want to compute L(n-1)  Afterwards, the matrix should not change anymore: L(n-1) = L(n) = L(n+1) = … δ(i, j) = L(n-1)[i, j] = L(n)[i, j] = L(n+1)[i, j]= …  Start from L(1) = W  Compute the solution in a bottom-up manner  L(1), L(2), …, L(k), …, L(n-1)
  • 12. Simple DP Algorithm – Pseudocode SLOW-APSP(G, W) n = |V[G]| L[1] = W FOR (m=2; m < n; m++) L[m] = EXPAND(L[m-1], W, n) RETURN L[n-1] EXPAND (L, W, n) L’ = new matrix(n, n) FOR (i=1; i <= n; i++) FOR (j=1; j <= n; j++) L’[i][j] = INF FOR (k=1; k <= n; k++) L’[i][j] = min(L’[i][j], L[i][k] + w[k][j]) RETURN L’ Time complexity: EXPAND - (n3) SLOW-APSP - (n4)  not very good! Same as Bellman-Ford - n times! Space complexity: uses n matrices - (n3)  can be reduced by using the same matrix L
  • 13. Improved Simple DP Algorithm  Improve the way L(n-1) is computed  Instead of computing: L(1), L(2), …, L(k), …, L(n-1)  Why not compute? L(1), L(2), L(4), …, L(2^k), …, L(2^r)  Stop when r = ceiling(log(n-1)) >= n-1, but this is ok!  EXPAND is similar to matrix multiplication C = A * B  L A  W B  L’ C  min +  + *  INF 0
  • 14. Improved DP Algorithm – Pseudocode FAST-APSP(G, W) n = |V[G]| L[1] = W m=1 FOR (; m < n; m=2*m) L[2*m] = EXPAND(L[m], L[m], n) RETURN L[m] EXPAND (L, W, n) L’ = new matrix(n, n) FOR (i=1; i <= n; i++) FOR (j=1; j <= n; j++) L’[i][j] = INF FOR (k=1; k <= n; k++) L’[i][j] = min(L’[i][j], L[i][k] + w[k][j]) RETURN L’ Time complexity: EXPAND - (n3) FAST-APSP - (n3 * logn)  Still not very good! But better than Bellman-Ford - n times! Space complexity: uses n matrices - (n3)  can be reduced by using the same matrix L
  • 15. Floyd-Warshall Algorithm  Use another DP formulation  Given a path p = <v1, v2, … , vj>  Any vertex except v1 and vj are intermediate vertices  Sub-problem: which is the shortest path between any two vertices that contain intermediate vertices in the set {1, 2, … , k} ?  D(k) = (D(k) [i, j]) for all 1 <= i, j <= n  We want to compute D(n)
  • 16. Floyd-Warshall – Recursive Formulation  Initialization (stop condition for the recursion):  D(0) = W  If no intermediate vertices are allowed, the best path between any two vertices is either the weight of the edge (if it exists) or INF  Recursive formulation: D(k)[i, j] = min(D(k-1)[i, j], D(k-1)[i, k] + D(k-1)[k, j])  Choose between:  The shortest path between i and j that contains intermediate vertices in {1, 2, … , k-1}  The sum of the shortest paths from i to k and from k to j that contain intermediate vertices in {1, 2, … , k-1}
  • 17. Floyd-Warshall – Recursive Formulation  The recursive formulation can be proved by induction  On whiteboard  Can also compute P(k)  How?  Compute the solution in a bottom-up fashion  D(0), D(1),…, D(k),…, D(n)
  • 18. Floyd-Warshall – Pseudocode FLOYD-WARSHALL(G, W) n = |V[G]| D[0] = W FOR (i = 1; i <= n; i++) FOR (j = 1; j <= n; j++) IF (w(i, j) != INF) P[0][i][j] = i ELSE P[0][i][j] = NIL FOR (k = 1; k <= n; k++) FOR (i = 1; i <= n; i++) FOR (j = 1; j <= n; j++) IF (D[k-1][i][j] < D[k-1][i][k] + D[k-1][k][j]) D[k][i][j] = D[k-1][i][j] P[k][i][j] = P[k-1][i][j] ELSE D[k][i][j] = D[k-1][i][k] + D[k-1][k][j] P[k][i][j] = P[k-1][k][j] RETURN D[n] Time complexity: (n3)  good for dense graphs and for graphs with negative weights Space complexity: (n3)  can be reduced to (n2) by using a single D matrix and a single P matrix
  • 19. Example (1) 0 3 8 ∞ -4 2 3 4 ∞ 0 ∞ 1 7 7 8 D(0) = ∞ 4 0 ∞ ∞ 1 3 2 ∞ -5 0 ∞ -4 2 1 ∞ ∞ ∞ 6 0 -5 5 4 6 nil 1 1 nil 1 nil nil nil 2 2 P(0) = nil 3 nil nil nil 4 nil 4 nil nil nil nil nil 5 nil Proiectarea Algoritmilor 2010
  • 20. Example (2) 0 3 8 ∞ -4 0 3 8 ∞ -4 ∞ 0 ∞ 1 7 ∞ 0 ∞ 1 7 D= ∞ 4 0 ∞ ∞ D= ∞ 4 0 ∞ ∞ 2 ∞ -5 0 ∞ 2 5 -5 0 -2 2 ∞ ∞ ∞ 6 0 3 4 ∞ ∞ ∞ 6 0 7 8 1 3 D(0), P(0) D(1), P(1) -4 1 2 -5 nil 1 1 nil 1 5 6 4 nil 1 1 nil 1 nil nil nil 2 2 nil nil nil 2 2 p = nil 3 nil nil nil p = nil 3 nil nil nil 4 nil 4 nil nil 4 1 4 nil 1 nil nil nil 5 nil nil nil nil 5 nil Proiectarea Algoritmilor 2010
  • 21. Example (3) 0 3 8 ∞ -4 0 3 8 4 -4 ∞ 0 ∞ 1 7 ∞ 0 ∞ 1 7 D= ∞ 4 0 ∞ ∞ D= ∞ 4 0 5 11 2 5 -5 0 -2 2 5 -5 0 -2 2 ∞ ∞ ∞ 6 0 3 4 ∞ ∞ ∞ 6 0 7 8 1 3 D(1), P(1) D(2), P(2) -4 1 2 -5 nil 1 1 nil 1 5 6 4 nil 1 1 2 1 nil nil nil 2 2 nil nil nil 2 2 p = nil 3 nil nil nil p = nil 3 nil 2 2 4 1 4 nil 1 4 1 4 nil 1 nil nil nil 5 nil nil nil nil 5 nil Proiectarea Algoritmilor 2010
  • 22. Example (4) 0 3 8 4 -4 0 3 8 4 -4 ∞ 0 ∞ 1 7 ∞ 0 ∞ 1 7 D= ∞ 4 0 5 11 D= ∞ 4 0 5 11 2 5 -5 0 -2 2 -1 -5 0 -2 2 ∞ ∞ ∞ 6 0 3 4 ∞ ∞ ∞ 6 0 7 8 1 3 D(2), P(2) D(3), P(3) -4 1 2 -5 nil 1 1 2 1 5 6 4 nil 1 1 2 1 nil nil nil 2 2 nil nil nil 2 2 p = nil 3 nil 2 2 p = nil 3 nil 2 2 4 1 4 nil 1 4 3 4 nil 1 nil nil nil 5 nil nil nil nil 5 nil Proiectarea Algoritmilor 2010
  • 23. Example (5) 0 3 8 4 -4 0 3 -1 4 -4 ∞ 0 ∞ 1 7 3 0 -4 1 -1 D= ∞ 4 0 5 11 D= 7 4 0 5 3 2 -1 -5 0 -2 2 -1 -5 0 -2 2 ∞ ∞ ∞ 6 0 3 4 8 5 1 6 0 7 8 1 3 D(3), P(3) D(4), P(4) -4 1 2 -5 nil 1 1 2 1 5 4 nil 1 4 2 1 6 nil nil nil 2 2 4 nil 4 2 1 p = nil 3 nil 2 2 p= 4 3 nil 2 1 4 3 4 nil 1 4 3 4 nil 1 nil nil nil 5 nil 4 3 4 5 nil Proiectarea Algoritmilor 2010
  • 24. Example (6) 0 3 -1 4 -4 0 1 -3 2 -4 3 0 -4 1 -1 3 0 -4 1 -1 D= 7 4 0 5 3 D= 7 4 0 5 3 2 -1 -5 0 -2 2 -1 -5 0 -2 2 8 5 1 6 0 3 4 8 5 1 6 0 7 8 D(4), P(4) 1 3 D(5), P(5) -4 1 2 -5 nil 1 4 2 1 5 4 nil 3 4 5 1 6 4 nil 4 2 1 4 nil 4 2 1 p= 4 3 nil 2 1 p= 4 3 nil 2 1 4 3 4 nil 1 4 3 4 nil 1 4 3 4 5 nil 4 3 4 5 nil Proiectarea Algoritmilor 2010
  • 25. Johnson’s Algorithm  We want to find an algorithm that works better than F-W for sparse graphs  Use SSSP algorithms  No negative edges: use Dijkstra – n times  (n2*logn)  Problem if we have negative weight edges  cannot use Dijkstra  B-F – n times is not good enough  (n3)  Therefore, we want to find an (n2*logn) algorithm that works on both positive and negative weight edges!  Combines Bellman-Ford and Dijkstra
  • 26. Johnson’s Algorithm – Idea  We would like:  To transform any negative-weighted graph into a graph with positive weights  Such that the minimum path using the new weights is the same path for the original weights  (G, W) => (G, W1)  w(u, v) can be negative  w1(u, v) >= 0 for all (u, v)  p is a minimum path u..v in (G, W) => p is also a minimum path u..v in (G, W1)
  • 27. How to Compute W1?  Computing W1 is not so simple  Simplistic idea:  Find the minimum negative weight edge  Add the absolute value of that weight to all the other weights in the graph  Then, these new weights are always >= 0 3 b 10 b a 8 a 15 5 12 c c d -7 d 0 Look at w(abd) in the two graphs This idea does not work!
  • 28. How to Compute W1? Use B-F  New idea: build a new graph G’(V’, E’)  V’ = V U {s}  E’ = E U {(s, v) for all vV}  w’(s, v) = 0 for all vV  w’(u, v) = w(u, v) for all u,vV  Run Bellman-Ford on G’ from s  The result is h(v)= δ(s, v) in G’ for all vV  h(v) may be positive or negative  We can also detect the negative cycles in G’  The new weight function for G is:  w1(u, v) = w(u, v) + h(u) – h(v) >= 0 for all (u, v)E
  • 29. Properties of G’ and W1  For any path p = <v0, v1, …, vk> in G:  w1(p) = w(p) + h(v0) – h(vk)  The negative weight cycles in G’ are the same as the negative weight cycles in G. Why?  Because the weight of all the cycles is the same for w1 as for w  Cycle p => v0 = vk => w1(p) = w(p)  Prove that w1(u, v) = w(u, v) + h(u) – h(v) >= 0 for all (u, v)E  Use triangle inequality for edge (u, v)E  In G’, we have h(v) = δ(s, v) <= h(u) + w(u, v) = δ(s, u) + w(u, v)  Therefore h(u) + w(u, v) – h(v) >= 0
  • 30. Johnson’s Algorithm – Pseudocode JOHNSON(G, W) G’ = (V’,E’); V’ = V  {s}; // add new source s E’ = E  (s,u), uV; w’(s,u) = 0; IF (BF(G’, W’) == FALSE) // run BF on G’ PRINT “Error! Negative cycle was found!” ELSE FOREACH (vV) h(v) = δ(s,v); // computed by Bellman Ford FOREACH ((u,v)E) w1(u,v) = w(u,v) + h(u) - h(v) // compute new positive weights FOREACH (uV) Dijkstra(G,w1,u) // run Dijkstra for each vertex as a source using w1 FOREACH (vV) d(u,v) = δ1(u,v) + h(v) - h(u) // we need to switch back from w1 to w Time complexity: (n*m + n2*logn)  (n2 * logn) for sparse graphs
  • 31. Example (1) 0 -1 2 0 2 3 4 3 4 7 0 0 7 0 8 -5 8 s 1 3 1 3 1 1 2 0 -4 2 -4 -5 -5 5 4 5 4 6 0 6 0 Add s and run -4 B-F on the new graph. Proiectarea Algoritmilor 2010
  • 32. Example (2) 0 -1 0 2 3 4 0 0 7 0 8 -5 s 1 3 5 -1 1 0 -4 2 1 -5 2 5 4 4 0 0 6 0 0 0 10 -4 0 13 -5 s 1 3 0 4 0 2 0 w1(u,v) = w(u,v) + h(u) - h(v) 5 4 0 2 0 -4 Proiectarea Algoritmilor 2010
  • 33. Example (3) 5 -1 2/1 1 2 2 4 0 0 0 4 0 10 -5 0/0 2/-3 0 13 10 s 1 3 13 1 3 0 4 0 2 0 0 0 2 0 5 4 0 2 0 5 4 -4 2 0/-4 2/2 Remove s Run Dijkstra from each vertex => (δ1(u, v)). Recompute the distances: d(u,v) = δ1(u,v) + h(v) - h(u) Proiectarea Algoritmilor 2010
  • 34. Example (4) 0/0 0/4 2 2 4 0 4 0 2/3 10 0/-4 2/7 10 0/0 13 13 1 3 1 3 0 2 0 0 2 0 0 1 -3 2 -4 0 0 5 4 3 0 -4 1 -1 5 4 2 2 2/-1 0/1 7 4 0 5 3 2/3 0/5 0/-1 2 -1 -5 0 -2 2/5 2 2 4 0 8 5 1 6 0 4 0 2/2 10 0/-5 4/8 10 2/1 13 13 1 3 1 3 2 0 2 0 0 0 0 0 5 4 5 4 2 2 2/-2 0/0 0/0 2/6 Proiectarea Algoritmilor 2010
  • 35. Application: Transitive Closure  Given a graph G(V, E)  Compute the transitive closure of G: G*(V, E*)  E* = {(u, v) | there exists at least a path in G from u to v, u..v}  G* is an unweighted graph  we only need to compute E* or the adjacency matrix of G*  We can use different algorithms  One algorithm is an adapted version of Floyd- Warshall  Initialize A(0)[i, j] = 1 if (i, j)E and A(0)[i, j] = 0 o/w  A(k)[i, j] = A(k-1)[i, j] OR (A(k-1)[i, k] AND A(k-1)[k, j])
  • 36. Transitive Closure – Pseudocode TRANSITIVE-CLOSURE(G, W) n = |V[G]| FOR (i = 1; i <= n; i++) FOR (j = 1; j <= n; j++) IF (W[i][j] != INF) A[0][i][j] = 1 ELSE A[0][i][j] = 0 FOR (k = 1; k <= n; k++) FOR (i = 1; i <= n; i++) FOR (j = 1; j <= n; j++) A[k][i][j] = A[k-1][i][j] OR (A[k-1][i][k] AND A[k-1][k][j]) RETURN A[n]
  • 37. Conclusions  We can use SSSP algorithms for computing APSP  But there are better solutions specific to the APSP problem!  Floyd-Warshall for dense graphs: (n3)  Johnson for sparse graphs: (n2 * logn)
  • 38. References  CLRS – Chapter 25  R. Sedgewick, K Wayne – Algorithms and Data Structures – Princeton 2007 www.cs.princeton.edu/~rs/AlgsDS07/  Problem 1 and the corresponding images are taken from these slides!  MIT OCW – Introduction to Algorithms – video lecture 19