2.1 Algorithms - PowerPoint PPT Presentation

1 / 57
About This Presentation
Title:

2.1 Algorithms

Description:

We will solve this problem by finding the length of the shortest path from a to ... The construction of Dodecahedron(?12??)the degree of every vertex is 3 and the ... – PowerPoint PPT presentation

Number of Views:78
Avg rating:3.0/5.0
Slides: 58
Provided by: cdr93
Category:

less

Transcript and Presenter's Notes

Title: 2.1 Algorithms


1
???????????????????????????
c
3
b
2
4
3
z
a
1
2
3
d
e
2
7.6 Shortest Path Problems
  • Example 1
  • What is the length of the shortest path between a
    and z in the weighted graph shown in Figure 3?
  • Solution Although the shortest path is easily
    found by inspection,we will develop some ideas
    useful in understanding Dijkstras algorithm. We
    will solve this problem by finding the length of
    the shortest path from a to successive vertices
    ,until z is reached.

3
  • The only paths starting at a that contain no
    vertex other than a (until the terminal vertex is
    reached)are a,b and a,d. Since the lengths of a,b
    and a,d are 4 and 2,respectively,it follows that
    d is the closest vertex to a .
  • We can find the next closest vertex by looking at
    all paths that go through only a and d (until the
    terminal vertex is reached ).The shortest such
    path to b is still a,b, with length 4,and the
    shortest such path to e is a,d,e,with length
    5.Consequently,the next closest vertex to a is b .

4
  • To find the third closest vertex to a, we need
    to examine only paths that go through only
    a,d,and b (until the terminal vertex is
    reached).There is a path of length 7 to
    c,namely,a,b,c,and a path of length 6 to z
    ,namely,a,d,e,z.Consequently,z is the next
    closest vertex to a, and the length of the
    shortest path to z is 6 .

5
Algorithm 1 Dijkstras Algorithm.
  • Procedure Dijkstra(G weighted connected simple
    graph, with all weights positive)
  • G has vertices a v0, v1 , ,vn z and
    weights w(vi ,vj )
  • where w(vi ,vj )8 if vi ,vj is not an
    edge in G
  • For I 1 to n
  • L(vi ) 8
  • L(a)0
  • S ø
  • the labels are now initialized so that the
    label of a is zero and all other labels are
    8,and S is the empty set

6
  • While z ? S
  • Begin
  • u a vertex not in S with L(u) minimal
  • SS? u
  • for all vertices v not in S
  • if L(u) w(u,v)ltL(v)L(u)w(u,v)
  • this adds a vertex to S with minimal label and
    updates the labels of vertices not in S
  • End L(z)length of shortest path from a to z

7
Example 2
5
b
d
2
4
1
8
a
2
z
2
3
c
9
e
8
l1 l2 l3 l4 l5
a
b 4 3 a
c 2 c
d 8 10 8 b
e 8 11 11 10 d
z 8 8 8 14 13 e

9
Theorem 1
  • Dijkstras algorithm finds the length of a
    shortest path between two vertices in a connected
    simple undirected weighted graph

10
Theorem 2
  • Dijkstras algorithm uses O(n2 )operations
    (additions and comparisons )to find the length of
    the shortest path between two vertices in a
    connected simple undirected weighted graph.

11
application
  • See another slide

12
7.7 Planar Graphs
  • Definition 1. A graph is called planar if it can
    be drawn in the plane without any edges crossing
    (where a crossing of edges is the intersection of
    the lines or arcs representing them at a point
    other than their common endpoint ).Such a drawing
    is called a planar representation of the graph.

13
Example 1
  • Is K4 (shown in Figure 2 with two edges crossing
    ) planar?
  • Solution K4 is planar because it can be drawn
    without crossings ,as shown in Figure 3.

14
Theorem 1
  • Eulers formula Let G be a connected planar
    simple graph with e edges and v vertices. Let r
    be the number of regions in a planar
    representation of G.Then re-v2.

15
  • Proof First ,we specify a planar representation
    of G.We will prove the theorem by constructing a
    sequence of subgraphs G1 , G2, , Ge
    G,successively adding an edge at each stage. This
    is done using the following inductive
    definition.Arbitrarily pick one edge of G to
    obtain G1.Obtain Gn from Gn-1 by arbitrarily
    adding an edge that is incident with a vertex
    already in Gn-1.

16
  • This construction is possible since G is
    connected. G is obtained after e edges are added.
    Let rn, en, and vn represent the number of
    regions, edges, and vertices of the planar
    representation of Gn induced by the planar
    representation of G,respectively.
  • The proof will now proceed by induction .The
    relationship r1 e1 v1 2 is true for G1,since
    e11, v1 2,and r1 1.This is shown in Figure 9.

17
  • Now assume that rn en vn 2 .Let an 1,bn1
    be the edge that is added to Gn to obtain Gn1.
    There are two possibilities to consider. In the
    first case,both an 1and bn1 and already in Gn .
    These two vertices must be on the boundary of a
    common region R, or else it would be impossible
    to add the edge an 1,bn1 to Gn without two
    edges crossing (and Gn1 is planar).The addition
    of this new edge splits R into two regions.

18
  • Consequently, in this case, rn1 rn 1 , en1
    en 1 ,and vn1 vn .Thus,each side of the
    formula relating the number of regions,edges ,and
    vertices increases by side of the formula
    relation the number of regions ,edges, and
    vertices increases by exactly one ,so this
    formula is still true. In other words, rn1
    en1 vn1 2 .This case is illustrated in
    Figure 10(a)

19
  • In the second case ,one of the two vertices of
    the new edge is not already in Gn. Suppose that
    an1 is in Gn but that bn1 is not .Adding this
    new edge does not produce any new regions,since
    bn1 must be in a region that has an1 on its
    boundary . Consequently, rn1 rn.Moreover, en1
    en 1and vn1 vn 1.Each side of the formula
    relating the number of regions ,edges, and
    vertices remains the same, so the formula is
    still true .In other words, rn1 en1 vn1 2
    .This case is illustrated in Figure 10(b)

20
  • We have completed the induction argument .Hence
    rn en vn 2 for all n. Since the original
    graph is the graph Ge,obtained after e edges have
    been added ,the theorem is true .

21
a
n1
a
n1
b
n1
b
n1
22
Example 4
  • Suppose that a connected planar simple graph has
    20 vertices, each of degree 3.Into how many
    regions does a representation of this planar
    graph split the plane ?
  • Solution This graph has 20 vertices ,each of
    degree 3,so that v20 . Since the sum of the
    degrees of the vertices, 3v 32060,is equal to
    twice the number of edges, 2e, we have 2e 60,or
    e 30. Consequently,from Eulers formula, the
    number of regions is
  • r e v 2 30-202 12.

23
Corollary 1
  • Degree of a region Suppose R is a region of a
    connected planar simple graph, the number of the
    edges which surround R is called the Degree of R
    , which denoted by Deg(R).
  • The region is a closed path.

24
c
R3
R2
b
d
R1
b
a
f
a
R1
R2
h
e
a
e
g
c
d
a
f
Deg(R1)3 Deg(R1)6 Deg(R1)7
Deg(R1)12 Deg(R2)4
25
Proof of Corollary 1
  • If G is a connected planar simple graph with e
    edges and v vertices where v3, then e3v-6
  • Proof suppose that a connected planar simple
    graph divides the plane into r regions, the
    degree of each region is at least 3. (no simple
    region can be surrounded by one or two different
    edges)

26
  • Note that the sum of the degrees of all the
    region of a connect graph G is exactly twice the
    number of the edges in the graph, because each
    edge occurs only on the boundary of one or two
    region of G exactly twice.(one time either in two
    different regions or twice in the same region).
    Hence,
  • 2e ?deg(Ri) 3r ,it imply r(2/3)e

27
  • Using Eulers formula e-v2r,we obtain
  • e-v2(2/3)e, this shows that
  • e 3v-6
  • The equality holds if and only every region has
    exactly three edges.

28
Example 5
  • Show that k5 is nonplanar using Corollary 1.
  • Solution The graph k5 has five vertices and 10
    edges. However,the inequality e ?3v-6 is not
    satisfied for this graph since e10 and
    3v-69.Therefore, k5 is not planar.

29
Corollary 2
  • If a connected planar simple graph has e edges
    and v vertices with v?3 and no circuits of length
    3,then e ?2v-4.
  • The proof of Corollary 2 is similar to that of
    Corollary 1,except that in this case the fact
    that there are no circuits of length 3 implies
    that the degree of a region must be at least
    4.The details of this proof are left for the
    reader (see Exercise 13 at the end of this
    section).

30
Example 6
  • Use Corollary 2 to show that K3,3 is nonplanar.
  • Solution Since K3,3 has no circuits of length 3
    (this is easy to see since it is
    bipartite),Corollary 2 can be used . K3,3 has
    six vertices and nine edges. Since e9 and
    2v-48,corollary 2 shows that K3,3 is nonplanar.

31
Corollary 3
  • Generally, if every region of a planar connected
    graph has at least l edges, then
  • e (v-2)
  • Proof similarly, 2e 2e ?deg(Ri) lr , this
    imply r(2/l)e, Using Eulers formula e-v2r,we
    obtain
  • e-v2 (2/l)e, this shows that
  • e (v-2)

32
  • The construction of Dodecahedron(?12??)the degree
    of every vertex is 3 and the degree of every
    region is 5, hence 2e3v, and
  • e (v-2)
    (v-2)(5/3)(v-2), hence
  • v20, e30 and r12

33
KURATOWSKIS THEOREM
  • Elementary subdivision

34
Theorem 2
  • A graph is nonplanar if and only if it
    contains a subgraph homeomorphic to K3,3 or K5.
  • It is clear that a graph containing a subgraph
    homeomorphic to K3,3 or K5 ,is complicated and
    will not be given here.The following examples
    illustrate how Kuratowskis theorem is used.
  • Hint homeomorphic is mainly adding or deleting a
    series if vertices of degree 2

35
Example 7
  • Determine whether the graph G shown in Figure 13
    is planar.(draw in board)
  • Solution G has a subgraph H homeomorphic to K5.
    H is obtained by deleting h,j,and k and all edges
    incident with these vertices. H is homeomorphic
    to K5 since it can be obtained from K5 (with
    vertices a,b,c,g,and I)by a sequence of
    elementary subdivisions ,adding the vertices
    d,e,and f .(The reader should construct such a
    sequence of elementary subdivisions.) Hence,G is
    nonplanar.

36
Example 8
  • Is the Petersen graph, shown in Figure
    14(a),planar?(The Danish mathematician Julius
    Petersen introduced this graph in 1891it is
    often used to illustrate various theoretical
    properties of graphs.)

37
a
f
c
a
f
j
b
e
g
j
g
a
h
i
e
i
h
d
c
38
  • Solution The subgraph H of the Petersen graph
    obtained by deleting b and the three edges that
    have b as an endpoint ,shown in Figure 14(b),is
    homeomorphic to K3,3, with vertex sets f,d,jand
    e,I,h,since it can be obtained by a sequence of
    elementary subdivisions,deleting d,h and adding
    c,h and c,d,deleting e,f and adding a,e
    and a,f,and deleting I,jand adding g,I and
    g,j.Hence,the Petersen graph is not planar.

39
Proof 2
  • In peterson graph, every simple circle has
    exactly 5 edges, if it is a planar graph, then
    the degree of every region is 5, hence e
    (v-2),
  • but e15,v10, (10-2)13.333, this
    leads to a contradiction.

40
7.8 Graph Coloring
  • Definition 1
  • A coloring of a simple graph is the assignment of
    a color to each vertex of the graph so that no
    two adjacent vertices are assigned the same color

41
  • Vertex coloring and region coloring
  • Dual graph A region to a vertex edges
    connect two vertices if the original regions are
    adjacent.
  • G(V,E), (1)G??????Fi????vi???
  • (2)?Fi?Fj??,?vi?vj??
  • (3)?e???Fi??????,?vi?????????

v1
5
v2
1
2
v5
4
3
v4
v3
42
Definition 2
  • The chromatic number of a graph G is the least
    number of colors needed for a coloring of this
    graph. Denoted by x(G)
  • (1) x(G1)3, (2)x(G2)2

.
.
.
.
.
.
.
43
Theorem 1
  • The Four Color Theorem The chromatic number of a
    planar graph is no greater than four.

44
Example 1
  • What are the chromatic numbers of the graphs G
    and H shown in Figure 3?
  • Solution The chromatic number of G is at least
    3,since the vertices a,b,and c must be assigned
    different colors. To see if G can be colored with
    three colors ,assign red to a,blue to b, and
    green to c.Then ,d can (and must )be colored red
    since it is adjacent to b and c .Furthermore,e
    can(and must )be colored green since it is
    adjacent only to vertices colored red and blue
    ,and f can (and must )be colored blue since it is
    adjacent only to vertices colored blue and
    green.This produces a coloring of G using exactly
    three colors.Figure 4 displays such a coloring.

45
.
.
.
.
.
.
.
.
.
.
.
.
.
.
46
  • The graph H is made up of the graph G with an
    edge connecting a and g.Any attempt to color H
    using three colors must follow the same reasoning
    as that used to color G ,except at the last
    stage, when all vertices other than g have been
    colored .Then ,since g is adjacent (in H)to
    vertices colored red ,blue,and green,a fourth
    color,say brown,needs to be used.Hence,H has a
    chromatic number equal to 4. A coloring of H is
    shown in Figure 4.

47
Example 2
  • What is the chromatic number of Kn?
  • SolutionA coloring of Kn can be constructed
    using n colors by assigning a different color to
    each vertex.Is there a coloring using fewer
    colors ?The answer is no.No two vertices can be
    assigned the same color ,since every two vertices
    of this graph are adjacent.Hence,the chromatic
    number of Kn n.(Recall that Kn is not planar
    when n?5,so this result does not contradict the
    four color theorem.)A coloring of K5 using five
    colors is shown in Figure 5.

48
  • X(k5)5,generally, X(Kn)n

.
.
.
.
.
49
Example 3
  • What is the chromatic number of the complete
    bipartite graph Km,n, where m and n are positive
    integers?
  • SolutionThe number of colors needed may seem to
    depend on m and n .However,only two colors are
    needed.Color the set of m vertices with one color
    and the set of n vertices with a second
    color.Since edges connect only a vertex from the
    set of m vertices and a vertex from the set of n
    vertices,no two adjacent vertices have the same
    color.A coloring of K3,4 with two colors is
    displayed in Figure 6.

50
  • X(Km,n)2

.
.
.
.
.
.
.
51
Example 4
  • What is the chromatic number of graph Cn ?(Recall
    that Cn is the cycle with n vertices.)
  • SolutionWe will first consider some individual
    cases.To begin, let n6.Pick a vertes and color
    it red .Proceed clockwise in the planar depiction
    of C6 show in Figure 7.It is necessary to assign
    a second color,say blue,to the next vertex
    reached. Continue in the clockwise directionthe
    third vertex can be colored red ,the fourth
    vertex blue, and the fifth vertex red.Finally,the
    sixth vertex,which is adjacent to the first,can
    be colored blue. Hence,the chromatic number of C6
    is 2.Figure 7 displays the coloring constructed
    here.

52
  • Next ,let n5 and consider C5. Pick a vertex and
    color it red . Proceeding clockwise,it is
    necessary to assign a second color ,say blue,to
    the next vertex reached. Continuing in the
    clockwise direction,the third vertex can be
    colored red, and the fourth vertex can be colored
    blue .The fifth vertex cannot be colored either
    red or blue,since it is adjacent to the fourth
    vertex and the first vertex.

53
  • Consequently,a third color is required for this
    vertex.Note that we would have also needed three
    colors if we had colored vertices in the
    counterclockwise direction.Thus,the chromatic
    number of C5 is 3.A coloring of C5 using three
    colors is displayed in Figure 7.
  • In general,two colors are needed to color Cn when
    n is even.To construct such a coloring ,simply
    pick a vertex and color it red.Then proceed
    around the graph in a clockwise direction(using a
    planar representation of the graph) coloring the
    second vertex blue,the third vertex red ,and so
    on.The nth vertex can be colored blue,since the
    two vertices adjacent to it,namely,the first and
    (n-1)st.Hence,a third color must be used

54
  • X(C2n1)3, X(C2n)2

.
.
.
.
.
.
.
.
.
.
.
55
  • When n is odd and ngt1,the chromatic number of Cn
    is 3.To see this ,pick an initial vertex. To use
    only two colors,it is necessary to alternate
    color as the graph is traversed in a clockwise
    direction.However,then nth vertex reached is
    adjacent to two vertices of different colors
    ,namely,the first and (n-1)st. Hence,a third
    color must be used.

56
application
  1. Scheduling Final Exam
  2. Frequency Assignments
  3. Index Register

1
2
7
6
3
5
4
57
  • Exercise p498-500 2, 17, 26
  • pp.508 7?10?20
  • pp.517 11?15
Write a Comment
User Comments (0)
About PowerShow.com