Eular Path

Embed Size (px)

Citation preview

  • 8/10/2019 Eular Path

    1/66

    Euler Paths and Euler Circuits

    An Euler path is a path that uses every edge of a graphexactly once.

    An Euler circuit is a circuit that uses every edge of a graphexactly once.

    An Euler path starts and ends at differentvertices. An Euler circuit starts and ends atthe samevertex.

  • 8/10/2019 Eular Path

    2/66

    Euler Paths and Euler Circuits

    B

    C

    DE

    A

    B

    C

    DE

    A

    An Euler path: BBADCDEBC

  • 8/10/2019 Eular Path

    3/66

    Euler Paths and Euler Circuits

    B

    C

    DE

    A

    B

    C

    DE

    A

    Another Euler path: CDCBBADEB

  • 8/10/2019 Eular Path

    4/66

    Euler Paths and Euler Circuits

    B

    C

    DE

    A

    B

    C

    DE

    A

    An Euler circuit: CDCBBADEBC

  • 8/10/2019 Eular Path

    5/66

    Euler Paths and Euler Circuits

    B

    C

    DE

    A

    B

    C

    DE

    A

    Another Euler circuit: CDEBBADC

  • 8/10/2019 Eular Path

    6/66

    Euler Paths and Euler Circuits

    Is it possible to determine whether a graph has an

    Euler path or an Euler circuit, without necessarilyhaving to find one explicitly?

  • 8/10/2019 Eular Path

    7/66

    The Criterion for Euler Paths

    Suppose that a graph has an Euler path P.

  • 8/10/2019 Eular Path

    8/66

    The Criterion for Euler Paths

    Suppose that a graph has an Euler path P.

    For every vertex vother than the starting and ending vertices,the path P enters v thesamenumber of times that it leaves v

    (say s times).

  • 8/10/2019 Eular Path

    9/66

    The Criterion for Euler Paths

    Suppose that a graph has an Euler path P.

    For every vertex vother than the starting and ending vertices,the path P enters v thesamenumber of times that it leaves v

    (say s times).

    Therefore, there are 2s edges having vas an endpoint.

  • 8/10/2019 Eular Path

    10/66

    The Criterion for Euler Paths

    Suppose that a graph has an Euler path P.

    For every vertex vother than the starting and ending vertices,the path P enters v thesamenumber of times that it leaves v

    (say s times).

    Therefore, there are 2s edges having vas an endpoint.

    Therefore, all vertices other than the two endpoints ofP must be even vertices.

  • 8/10/2019 Eular Path

    11/66

    The Criterion for Euler Paths

    Suppose the Euler path Pstarts at vertex xand ends at y.

  • 8/10/2019 Eular Path

    12/66

    The Criterion for Euler Paths

    Suppose the Euler path Pstarts at vertex xand ends at y.

    Then P leaves xone more time than it enters, and leaves yone fewer time than it enters.

  • 8/10/2019 Eular Path

    13/66

    The Criterion for Euler Paths

    Suppose the Euler path Pstarts at vertex xand ends at y.

    Then P leaves xone more time than it enters, and leaves yone fewer time than it enters.

    Therefore, the two endpoints of P must be odd vertices.

  • 8/10/2019 Eular Path

    14/66

    The Criterion for Euler Paths

    The inescapable conclusion (based on reason alone!):

    If a graph G has an Euler path, then it must have

    exactly two odd vertices.

    Or, to put it another way,

    If the number of odd vertices in G is anything other

    than 2, then Gcannot have an Euler path.

  • 8/10/2019 Eular Path

    15/66

    The Criterion for Euler Circuits

    Suppose that a graph Ghas an Euler circuit C.

  • 8/10/2019 Eular Path

    16/66

    The Criterion for Euler Circuits

    Suppose that a graph Ghas an Euler circuit C.

    For every vertex v in G, each edge having vas an

    endpoint shows up exactly once in C.

  • 8/10/2019 Eular Path

    17/66

    The Criterion for Euler Circuits

    Suppose that a graph Ghas an Euler circuit C.

    For every vertex v in G, each edge having vas an

    endpoint shows up exactly once in C.

    The circuit C enters vthe same number of times that itleaves v (say s times), so vhas degree 2s.

  • 8/10/2019 Eular Path

    18/66

    The Criterion for Euler Circuits

    Suppose that a graph Ghas an Euler circuit C.

    For every vertex v in G, each edge having vas an

    endpoint shows up exactly once in C.

    The circuit C enters vthe same number of times that itleaves v (say s times), so vhas degree 2s.

    That is, v must be an even vertex.

  • 8/10/2019 Eular Path

    19/66

    The Criterion for Euler Circuits

    The inescapable conclusion (based on reason alone):

    If a graphGhas an Euler circuit, then all of its vertices

    must be even vertices.

    Or, to put it another way,

    If the number of odd vertices in G is anything other

    than 0, then G cannot have an Euler circuit.

  • 8/10/2019 Eular Path

    20/66

    Things You Should Be Wondering

    Does every graph with zero odd vertices have an Eulercircuit?

    Does every graph with two odd vertices have an Eulerpath?

    Is it possible for a graph have just one odd vertex?

  • 8/10/2019 Eular Path

    21/66

    How Many Odd Vertices?

  • 8/10/2019 Eular Path

    22/66

    How Many Odd Vertices?

    Odd vertices

  • 8/10/2019 Eular Path

    23/66

    How Many Odd Vertices?

    86

    2 4 8

    6Number of odd vertices

  • 8/10/2019 Eular Path

    24/66

    The Handshaking Theorem

    The Handshaking Theorem says that

    In every graph, the sum of the degrees of all vertices

    equals twice the number of edges.

    If there are n vertices V1, . . . , Vn, with degrees d1, . . . , dn, andthere are eedges, then

    d1+d2+ +dn1+dn = 2e

    Or, equivalently,

    e= d1+d2+ +dn1+dn

    2

  • 8/10/2019 Eular Path

    25/66

    The Handshaking Theorem

    Why Handshaking?

    Ifn people shake hands, and the ith person shakes hands ditimes, then the total number of handshakes that take place is

    d1+d2+ +dn1+dn2

    .

    (How come? Each handshake involves two people, so thenumber d1+d2+ +dn1+dn counts every handshaketwice.)

  • 8/10/2019 Eular Path

    26/66

    The Number of Odd Vertices

    The number of edges in a graph is

    d1+d2+ +dn2

    which must be an integer.

  • 8/10/2019 Eular Path

    27/66

    The Number of Odd Vertices

    The number of edges in a graph is

    d1+d2+ +dn2

    which must be an integer.

    Therefore, d1+d2+ +dn must be an even number.

  • 8/10/2019 Eular Path

    28/66

    The Number of Odd Vertices

    The number of edges in a graph is

    d1+d2+ +dn2

    which must be an integer.

    Therefore, d1+d2+ +dn must be an even number.

    Therefore, the numbers d1, d2, , dn must include aneven number of odd numbers.

  • 8/10/2019 Eular Path

    29/66

    The Number of Odd Vertices

    The number of edges in a graph is

    d1+d2+ +dn2

    which must be an integer.

    Therefore, d1+d2+ +dn must be an even number.

    Therefore, the numbers d1, d2, , dn must include aneven number of odd numbers.

    Every graph has an even number of odd vertices!

  • 8/10/2019 Eular Path

    30/66

    Back to Euler Paths and Circuits

    Heres what we know so far:

    # odd vertices Euler path? Euler circuit?

    0 No Maybe2 Maybe No

    4, 6, 8, . . . No No

    1, 3, 5, . . . No such graphs exist!

    Can we give a better answer than maybe?

  • 8/10/2019 Eular Path

    31/66

    Euler Paths and Circuits The Last Word

    Here is the answer Euler gave:

    # odd vertices Euler path? Euler circuit?

    0 No Yes*

    2 Yes* No4, 6, 8, . . . No No

    1, 3, 5, No such graphs exist

    * Provided the graph is connected.

  • 8/10/2019 Eular Path

    32/66

    Euler Paths and Circuits The Last Word

    Here is the answer Euler gave:

    # odd vertices Euler path? Euler circuit?

    0 No Yes*

    2 Yes* No4, 6, 8, . . . No No

    1, 3, 5, No such graphs exist

    * Provided the graph is connected.

    Next question: If an Euler path or circuit exists, how do

    you find it?

    B d

  • 8/10/2019 Eular Path

    33/66

    Bridges

    Removing a single edge from a connected graph can make it

    disconnected. Such an edge is called a bridge.

    B id

  • 8/10/2019 Eular Path

    34/66

    Bridges

    Removing a single edge from a connected graph can make it

    disconnected. Such an edge is called a bridge.

    B id

  • 8/10/2019 Eular Path

    35/66

    Bridges

    Removing a single edge from a connected graph can make it

    disconnected. Such an edge is called a bridge.

    B id

  • 8/10/2019 Eular Path

    36/66

    Bridges

    Loops cannot be bridges, because removing a loop from agraph cannot make it disconnected.

    deleteloop e

    e

    B id

  • 8/10/2019 Eular Path

    37/66

    Bridges

    If two or more edges share both endpoints, then removing anyone of them cannot make the graph disconnected. Therefore,none of those edges is a bridge.

    edgesA

    C

    D

    B

    multipledelete

    B id

  • 8/10/2019 Eular Path

    38/66

    Bridges

    If two or more edges share both endpoints, then removing anyone of them cannot make the graph disconnected. Therefore,none of those edges is a bridge.

    edgesA

    C

    D

    B

    multipledelete

    Finding E ler Circ its and Paths

  • 8/10/2019 Eular Path

    39/66

    Finding Euler Circuits and Paths

    Dont burn your bridges.

    Finding Euler Circuits and Paths

  • 8/10/2019 Eular Path

    40/66

    Finding Euler Circuits and Paths

    Problem: Find an Euler circuit in the graph below.

    A

    B

    FE

    DC

    Finding Euler Circuits and Paths

  • 8/10/2019 Eular Path

    41/66

    Finding Euler Circuits and Paths

    There are two odd vertices, A and F. Lets start at F.

    A

    B

    FE

    DC

    Finding Euler Circuits and Paths

  • 8/10/2019 Eular Path

    42/66

    Finding Euler Circuits and Paths

    Start walking at F. When you use an edge, delete it.

    A

    B

    FE

    DC

    Finding Euler Circuits and Paths

  • 8/10/2019 Eular Path

    43/66

    Finding Euler Circuits and Paths

    Path so far: FE

    A

    B

    FE

    DC

    Finding Euler Circuits and Paths

  • 8/10/2019 Eular Path

    44/66

    Finding Euler Circuits and Paths

    Path so far: FEA

    A

    B

    FE

    DC

    Finding Euler Circuits and Paths

  • 8/10/2019 Eular Path

    45/66

    Finding Euler Circuits and Paths

    Path so far: FEAC

    A

    B

    FE

    DC

    Finding Euler Circuits and Paths

  • 8/10/2019 Eular Path

    46/66

    Finding Euler Circuits and Paths

    Path so far: FEACB

    A

    B

    FE

    DC

    Finding Euler Circuits and Paths

  • 8/10/2019 Eular Path

    47/66

    Finding Euler Circuits and Paths

    Up until this point, the choices didnt matter.

    Finding Euler Circuits and Paths

  • 8/10/2019 Eular Path

    48/66

    Finding Euler Circuits and Paths

    Up until this point, the choices didnt matter.

    But now, crossing the edge BA would be a mistake, becausewe would be stuck there.

    Finding Euler Circuits and Paths

  • 8/10/2019 Eular Path

    49/66

    Finding Euler Circuits and Paths

    Up until this point, the choices didnt matter.

    But now, crossing the edge BA would be a mistake, becausewe would be stuck there.

    The reason is that BA is a bridge. We dont want to cross(burn?) a bridge unless it is the only edge available.

    Finding Euler Circuits and Paths

  • 8/10/2019 Eular Path

    50/66

    g u u s s

    Path so far: FEACB

    A

    B

    FE

    DC

    Finding Euler Circuits and Paths

  • 8/10/2019 Eular Path

    51/66

    g

    Path so far: FEACBD.

    A

    B

    FE

    DC

    Finding Euler Circuits and Paths

  • 8/10/2019 Eular Path

    52/66

    g

    Path so far: FEACBD. Dont cross the bridge!

    A

    B

    FE

    DC

    Finding Euler Circuits and Paths

  • 8/10/2019 Eular Path

    53/66

    g

    Path so far: FEACBDC

    A

    B

    FE

    DC

    Finding Euler Circuits and Paths

  • 8/10/2019 Eular Path

    54/66

    g

    Path so far: FEACBDC Now we have to cross the bridge CF.

    A

    B

    FE

    DC

    Finding Euler Circuits and Paths

  • 8/10/2019 Eular Path

    55/66

    Path so far: FEACBDCF

    A

    B

    FE

    DC

    Finding Euler Circuits and Paths

  • 8/10/2019 Eular Path

    56/66

    Path so far: FEACBDCFD

    A

    B

    FE

    DC

    Finding Euler Circuits and Paths

  • 8/10/2019 Eular Path

    57/66

    Path so far: FEACBDCFDB

    A

    B

    FE

    DC

    Finding Euler Circuits and Paths

  • 8/10/2019 Eular Path

    58/66

    Euler Path: FEACBDCFDBA

    A

    B

    FE

    DC

    Finding Euler Circuits and Paths

  • 8/10/2019 Eular Path

    59/66

    Euler Path: FEACBDCFDBA

    A

    B

    FE

    DC

    Fleurys Algorithm

  • 8/10/2019 Eular Path

    60/66

    To find an Euler path or an Euler circuit:

    Fleurys Algorithm

  • 8/10/2019 Eular Path

    61/66

    To find an Euler path or an Euler circuit:

    1. Make sure the graph has either 0 or 2 odd vertices.

    Fleurys Algorithm

  • 8/10/2019 Eular Path

    62/66

    To find an Euler path or an Euler circuit:

    1. Make sure the graph has either 0 or 2 odd vertices.

    2. If there are 0 odd vertices, start anywhere. If there are 2

    odd vertices, start at one of them.

    Fleurys Algorithm

  • 8/10/2019 Eular Path

    63/66

    To find an Euler path or an Euler circuit:

    1. Make sure the graph has either 0 or 2 odd vertices.

    2. If there are 0 odd vertices, start anywhere. If there are 2

    odd vertices, start at one of them.

    3. Follow edges one at a time. If you have a choice betweena bridge and a non-bridge,always choose the non-bridge.

    Fleurys Algorithm

  • 8/10/2019 Eular Path

    64/66

    To find an Euler path or an Euler circuit:

    1. Make sure the graph has either 0 or 2 odd vertices.

    2. If there are 0 odd vertices, start anywhere. If there are 2

    odd vertices, start at one of them.

    3. Follow edges one at a time. If you have a choice betweena bridge and a non-bridge,always choose the non-bridge.

    4. Stop when you run out of edges.

    Fleurys Algorithm

  • 8/10/2019 Eular Path

    65/66

    To find an Euler path or an Euler circuit:

    1. Make sure the graph has either 0 or 2 odd vertices.

    2. If there are 0 odd vertices, start anywhere. If there are 2

    odd vertices, start at one of them.

    3. Follow edges one at a time. If you have a choice betweena bridge and a non-bridge,always choose the non-bridge.

    4. Stop when you run out of edges.

    This is called Fleurys algorithm, and it always works!

    Fleurys Algorithm: Another Example

  • 8/10/2019 Eular Path

    66/66

    G

    K LJ M

    HE

    A

    F

    CB D

    NO P

    Q