Docstoc

Analysis of Algorithms_ 91

Document Sample
Analysis of Algorithms_ 91 Powered By Docstoc
					                                                Homework Set #2 + Selected Solutions

              Assigned: Tuesday, 9/25                                           Due: Part I: Tuesday, 10/2 (start of lecture)
                                                                                    Part II: Tuesday, 10/9 (start of lecture)

                       This assignment covers textbook material in Chapters 26-27,
                            plus review material from 91.404 in Chapters 23-25.
                    Note: Partial credit for wrong answers is only given if work is shown.


    Part I [Topics: 91.404 Graph Review, Chapters 25, 26] Due Tuesday, 10/2


    1. (15 points) Path Relaxation: Textbook, p. 526, Exercise 25.1-4


    2. (15 points) Bellman Ford Example: Textbook, p. 535, Exercise 25.3-1
                                                                                  (but no weight change or z source)


    SOL)      d(vertex) = vertexmax(i)

                  (u,v)        (u,x)           (u,y)   (v,u)           (x,v)       (x,y)              (y,v)       (y,z)       (z,u)   (z,x)             CH
          d        v1           x1              y1      u1              v2          y2                 v3           z          u2      x2
                                                                                                                                                         G
     1st           ∞            ∞               ∞          ∞            ∞              ∞                      7       2        8           9        YES
     2nd           7            9               0          5            6              0                      6       2        5           9        YES
     3rd           6            9               0          4            6              0                      6       2        5           9        YES
     4th           6            9               0          4            6              0                      6       2        4           9        NO


                                                                       u          5                   v                        u      5             v
              u           5            v
              ∞           -2           ∞                                8         -2                  7                        5      -2            6
      6                                                        6                                                          6
               8               -3                                        8                  -3                                  8              -3
z    ∞                                     7           z       2                                          7       z       2                             7
                               -4                                                           -4                                                 -4
                          2                                                       2                                                   2
      7                                                        7                                                          7
              ∞                        0                                9                             0                        9                    0
                          9                                                       9                                                   9
              x                        y                                x                             y                        x                    y


    (a) before first pass                                  (b) after 1st pass                                         (c) after 2nd pass



              u           5            v                                    u          5                  v
              4           -2           6                                    4          -2                 6
      6                                                            6
               8               -3                                            8                   -3
z    2                                     7               z       2                                          7
                               -4                                                                -4
                          2                                                            2
      7                                                            7
              9                        0                                    9                             0
                          9                                                            9
              x                        y                                    x                             y


    (d) after 3rd pass                                         (e) after 4th pass
3. (20 points) Bellman Ford: Textbook, p. 535, Exercise 25.3-3

   SOLUTION:




4. (15 points) Transitive Closure: p. 557, Exercise 26.1-3
5. (35 points) Transitive Closure: Textbook, p. 576, Problem 26-1.

  SOLUTION:
Part II    [Topics: Chapters 26, 27] Due Tuesday, 10/9


1. (20 points) Floyd-Warshall, Textbook, Exercise 26.2-1 on p.563.
SOL)
                            0    ∞   ∞   ∞    -1   ∞                  0    ∞   ∞    ∞   -1   ∞

                            1    0   ∞   2    ∞    ∞                  1    0   ∞    2   0    ∞
                  (0)                                       (1)
              D         =   ∞    2   0   ∞    ∞    -8   D         =   ∞    2   0    ∞   ∞    -8

                            -4   ∞   ∞   0    3    ∞                  -4   ∞   ∞    0   -5   ∞

                            ∞    7   ∞   ∞    0    ∞                  ∞    7   ∞    ∞   0    ∞

                            ∞    5   10 ∞     ∞    0                  ∞    5   10   ∞   ∞    0



                            0    ∞   ∞   ∞    -1   ∞                  0    ∞   ∞    ∞   -1   ∞

                            1    0   ∞   2    0    ∞                  1    0   ∞    2   0    ∞
                  (2)                                       (3)
              D         =   3    2   0   4    2    -8   D         =   3    2   0    4   2    -8

                            -4   ∞   ∞   0    -5   ∞                  -4   ∞   ∞    0   -5   ∞

                            8    7   ∞   9    0    ∞                  8    7   ∞    9   0    ∞

                            6    5   10 7     -5   0                  6    5   10   7   7    0



                            0    ∞   ∞   ∞    -1   ∞                  0    6   ∞    8   -1   ∞

                            -2   0   ∞   2    -3   ∞                  -2   0   ∞    2   -3   ∞
                  (4)                                       (5)
              D         =   0    2   0   4    -1   -8   D         =   0    2   0    4   -1   -8
                            -4   ∞   ∞   0    -5   ∞                  -4   2   ∞    0   -5   ∞

                            5    7   ∞   9    0    ∞                  5    7   ∞    9   0    ∞

                            3    5   10 7     2    0                  3    5   10   7   2    0



                            0    6   ∞   8    -1   ∞

                            -2   0   ∞   2    -3   ∞
                 (6)
             D         =    -5   -3 0    -1   -6   -8

                            -4   2   ∞   0    -5   ∞

                            5    7   ∞   9    0    ∞

                            3    5   10 7     2    0
2. (25 points) Floyd-Warshall, Textbook, Exercise 26.2-5 on p.565.
   SOLUTION:

SOL 1)
1) Check the main-diagonal entries of the result matrix.
2) There is a negative weight cycle iff dii(n-1) < 0 for some vertex i.
OR
SOL 2)
1) Run FLOYD-WARSHALL algorithm one extra iteration to see if any of the d values change.
2) If there are no negative cycles, then no d-values will change.
  3. (20 points) Network Flow, Textbook, Exercise 27.1-1 on p.586.

SOL)

           u                            u                      u                   u

     5          8                 3/5       8            3/5       4/8         5       1/8


           v                            v                      v                   v

The net flow from u to v = -1


4. (35 points) Network Flow, Textbook, Problem 27-5 on p.627, (a)-(c)
SOL)
    (a) (ref. p591) c(S,T)= capacity of the cut (S,T) = sum of the capacities of the edges
         crossing S to T. There are at most |E| edges and the capacity of each edge is at most C,
         the capacity of any cut of G is at most C|E|.
    (b) Do a BFS(Breadth-First-Search) or DFS(Depth-First-Search) to find the path,
         considering only edges with residual capacity at least K. This takes O(V+E) = O(E)
    (c) MAX-FLOW-BY-SCALING repeatedly augments the flow along an augmenting path until

         there are no augmenting paths of capacity ≥ 1. Since all the capacities are integers,
         and the capacity of an augmenting path is positive, this means that there are no
         augmenting paths in the residual network. Thus by the max-flow-min-cut theorem,
         MAX-FLOW-BY-SCALING returns a maximum flow.

				
DOCUMENT INFO