Chapter 8 Graph Optimization Problems - PowerPoint PPT Presentation

1 / 42
About This Presentation
Title:

Chapter 8 Graph Optimization Problems

Description:

(From 7.1 of Michael T. Goodrich & Roberto Tamassia) ... The distance from a vertex v to a vertex u in G, denoted d(v, u) is the length ... – PowerPoint PPT presentation

Number of Views:117
Avg rating:3.0/5.0
Slides: 43
Provided by: aiCePu
Category:

less

Transcript and Presenter's Notes

Title: Chapter 8 Graph Optimization Problems


1
Chapter 8Graph Optimization Problems Greedy
Algorithms
2
Single-Source Shortest Paths(From 7.1 of Michael
T. Goodrich Roberto Tamassia)
3
  • If a path P of a graph G consists of edges e0,
    e1,, ek1 then the length (or weight) of P,
    denoted w(P), is defined as
  • The distance from a vertex v to a vertex u in G,
    denoted d(v, u) is the length of a minimum
    length path (also called shortest path) from v to
    u, if such a path exists.
  • d(v, u) ? if there is no path from v to u
  • d(v, u) is undefined if there is a cycle in G
    whose total weight is negative.
  • One may go through the cycle as many times as he
    or she likes before going on to u.

4
Dijkstras Algorithm
  • Assumptions
  • The graph G is undirected.
  • G is simple (has no self-loops and no parallel
    edges).
  • The algorithm can easily be extended to the
    weighted directed graph.
  • Du the length of the best path found so far
    from v to u.
  • Initially, Dv 0 and Du ? for each u ? v.
  • C cloud of vertices.
  • C ? initially, and v is pulled into C in the
    first iteration.
  • At each iteration, a vertex u not in C with
    smallest Du is pulled into C. (? a greedy
    algorithm)

5
  • Once a new vertex u is pulled into C, we update
    Dz of each vertex z that is adjacent to u and
    is outside of C.
  • Edge relaxation
  • if Du w(u, z) ? Dz then Dz ? Du w(u,
    z)
  • ? Algorithm 7.2.
  • Dijkstras algorithm is greedy but optimal if
    there are no negative-weight edges in the graph.
  • Lemma 7.1 In Dijkstras algorithm, whenever a
    vertex u is pulled into the cloud, the label Du
    is equal to d(v, u), the length of a shortest
    path from v to u.

6
Algorithm 7.2 (p. 343)
7
Figure 7.3 (p. 344)
8
(No Transcript)
9
(No Transcript)
10
Figure 7.4 (p. 345)
11
(No Transcript)
12
Proof (Lemma 7.1) Let u be the first vertex the
algorithm pulled into C such that Du ? d(v,
u). Let P be the shortest path from v to u. Let
z be the first vertex of P (when going from v to
u) that is not in C at the moment when u is
pulled into C. Let y be the predecessor of z in
path P. (See Figure 7.5) We know, by our choice
of z, that y is already in C. Moreover, Dy
d(v, y), since u is the first incorrect
vertex. When y was pulled into C, we tested Dz
so that we had Dz ? Dy d(y, z) d(v, y)
d(y, z). But since z is the next vertex on P,
Dz d(v, z).
13
(No Transcript)
14
Proof (contd) But we are now at the moment of
picking u, not z, to join C hence, Du ?
Dz. Since z is on the shortest path from v to
u, d(v, z) d(z, u) d(v, u). Moreover, d(z,
u) ? 0 because there are no negative-weight
edges. Therefore, Du ? Dz d(v, z) ? d(v,
z) d(z, u) d(v, u). But this contradicts our
assumption on u hence there can be no such
vertex u.
15
  • The Running Time of Dijkstras Algorithm
  • Assume an adjacency list representation for G and
    a heap structure for the priority queue Q.
  • To insert all the vertices in Q O(n)
  • At each iteration of the while loop
  • O(log n) to remove vertex u from Q,
  • O(deg(u) log n) to perform the relaxation
    procedure on the edges incident on u. (log n to
    fix Q)
  • The overall running time of the while loop is

which is O((nm) log n).
16
  • Theorem 7.2 Given a weighted n-vertex graph G
    with m edges, each with a non-negative weight,
    Dijkstras algorithm can be implemented to find
    all shortest paths from a vertex v in G in O(m
    log n) time.
  • As a function of n only O(n2 log n) in the worst
    case.
  • An alternative implementation using an unsorted
    sequence for Q. (Assume the locator pattern is
    supported.)
  • ?(n) to extract the minimum element.
  • O(1) to perform key update in a relaxation step.
  • Overall running time of the while loop

which is O((n2m) ? O(n2).
17
  • Theorem 7.3 Given a simple weighted graph G with
    n vertices and m edges, such that the weight of
    each edge is non-negative, and a vertex v of G,
    Dijkstras algorithm computes the distance from v
    to all other vertices of G in O(m log n) time,
    or, alternatively in O(n2) time.
  • Looking only at the worst-case times, heap
    implementation is better when the number of edges
    in G is small (when m ? n2 / log n).

18
Minimum Spanning Trees(From 7.3 of Michael T.
Goodrich Roberto Tamassia)
19
  • Minimum spanning tree (MST) problem
  • Given a weighted graph G, find a tree T that
    contains all the vertices in G (i.e., a spanning
    tree) and minimizes the sum of the weights of the
    edges of T, that is,
  • Assumptions The graph G is undirected and
    simple.
  • Theorem 7.10 Let G be a weighted connected
    graph, and let V1 and V2 be a partition of the
    vertices of G into two disjoint nonempty sets.
    Furthermore, let e be an edge in G with minimum
    weight from among those with one endpoint in V1,
    and the other in V2. There is a minimum spanning
    tree T that has e as one of its edges.

20
Proof (Theorem 7.10) Let T be a minimum
spanning tree. If T does not contain edge e, the
addition of e to T must create a
cycle. Therefore, there is some edge f of this
cycle that has one endpoint in V1 and the other
in V2. Moreover, by the choice of e, w(e) ?
w(f). If we remove f from T ? e, we obtain a
spanning tree whose total weight is no more than
before. Since T was a minimum spanning tree,
this new tree must also be a minimum spanning
tree. ?
21
Kruskals Algorithm
  • Initially, each vertex is in its own cluster all
    by itself.
  • Considers each edge in turn, ordered by
    increasing weight.
  • If an edge e connects two different cluster, then
  • e is added to the set of edges of the minimum
    spanning tree, and
  • the two clusters connected by e are merged into a
    single cluster.
  • If, on the other hand, e connects two vertices
    that are already in the same cluster, then e is
    discarded.
  • Terminates once enough edges are added to form a
    spanning tree, and outputs this tree as the
    minimum spanning tree.

22
Algorithm 7.14 (p. 362)
23
Figure 7.15 (a) (b) (p. 363)
24
Figure 7.15 (c) (d) (p. 363)
25
Figure 7.15 (e) (f) (p. 363)
26
Figure 7.16 (g) (h) (p. 364)
27
Figure 7.16 (i) (j) (p. 364)
28
Figure 7.16 (k) (l) (p. 364)
29
Figure 7.17 (m) (n) (p. 365)
30
  • The correctness of Kruskals algorithm
  • Each time an edge (v, u) is added to T, we can
    define a partitioning of V by letting
  • V1 be the cluster containing v and letting
  • V2 contain the rest of the vertices in V.
  • This defines a disjoint partitioning of V.
  • Since we are extracting edges from Q in order by
    their weights, e must be a minimum-weight edge
    with one vertex in V1 and the other in V2.
  • Thus, Kruskals algorithm always adds a valid
    minimum-spanning-tree edge. (by Theorem 7.10)

31
  • Implementation of Kruskals algorithm
  • n of vertices, m of edges
  • Use a heap for the priority queue Q.
  • Can initialize Q in O(m) time by using bottom-up
    heap construction.
  • Can remove a minimum-weight edge in O(log m)
    time, which actually is O(log n).
  • O(log m) O(log n2) O(2log n) O(log n)
  • Use a list-based implementation of the clusters.
  • We represent each cluster with an unordered
    linked list of vertices, storing, with each
    vertex v, a reference to its cluster C(v).

32
  • With a list-based representation of the clusters
  • Testing whether C(u) ? C(v) takes O(1) time.
  • When merging C(u) and C(v),
  • we move the elements of the smaller cluster into
    the larger one and
  • update the cluster references of the smaller
    cluster
  • Takes O(minC(u), C(v)) time
  • Lemma 7.11 Consider an execution of Kruskals
    algorithm on a graph with n vertices, where
    clusters are represented with sequences and with
    cluster references at each vertex. The total time
    spent merging clusters is O(n log n).

33
Proof (Lemma 7.11) Each time a vertex is
moved to a new cluster, the size of the cluster
containing the vertex at least doubles. Let t(v)
be the number of times that vertex v is moved to
a new cluster. Since the maximum cluster size is
n, t(v) ? log n. Thus the total time spent
merging clusters is proportional to
34
  • Using Lemma 7.11 and arguments similar to those
    used in the analysis of Dijkstras algorithm, we
    conclude that the total running time of Kruskals
    algorithm is O((nm) log n), which can be
    simplified as O(m log n) since G is simple and
    connected.
  • Theorem 7.12 Given a simple connected weighted
    graph G with n vertices and m edges, Kruskals
    algorithm constructs a minimum spanning tree for
    G in time O(m log n).

35
The Prim-Jarník Algorithm
  • Similar to Dijkstras algorithm.
  • We begin with some vertex v, defining the initial
    cloud of vertices C.
  • Then, in each iteration, we choose a
    minimum-weight edge e (v, u), connecting a
    vertex v in C to a vertex u outside of C.
  • The vertex u is brought into C and the process is
    repeated until a spanning tree is formed.
  • We maintain a label Du for each vertex u
    outside C.
  • These labels allow us to reduce the number of
    edges we must consider in deciding which vertex
    is next to join C.

36
Algorithm 7.18 (p. 367)
37
  • n of vertices, m of edges
  • Use a heap for the locator-based priority queue
    Q.
  • Can extract the vertex u in each iteration in
    O(log n) time.
  • Can update each Dz value in O(log n) time,
    which is a computation considered at most once
    for each edge (u, z).
  • The other steps in each iteration O(1)
  • Total O((nm) log n)
  • Theorem 7.13 Given a simple connected weighted
    graph G with n vertices and m edges, the
    Prim-Jarník algorithm constructs a minimum
    spanning tree for G in O(m log n) time.

38
849
144
Figure 7.19 (a) (b) (p. 368)
39
187
187
621
740
Figure 7.19 (c) (d) (p. 368)
184
1391
1391
1090
946
40
621
1846
2704
Figure 7.19 (e) (f) (p. 368)
802
1391
946
946
41
1464
1464
Figure 7.20 (g) (h) (p. 369)
1235
1235
946
42
337
Figure 7.20 (i) (j) (p. 369)
Write a Comment
User Comments (0)
About PowerShow.com