+ All Categories
Home > Documents > 07e-HamiltoniannCycle

07e-HamiltoniannCycle

Date post: 04-Jun-2018
Category:
Upload: frankjamison
View: 217 times
Download: 0 times
Share this document with a friend

of 18

Transcript
  • 8/13/2019 07e-HamiltoniannCycle

    1/18

    Dr. Ahmad R. Hadaegh

    A.R. Hadaegh Cali for nia State University San Marcos (CSUSM) Page 1

    Hamiltonian

    Cycle

  • 8/13/2019 07e-HamiltoniannCycle

    2/18

    Dr. Ahmad R. Hadaegh

    A.R. Hadaegh Cali for nia State University San Marcos (CSUSM) Page 2

    Hamiltonian Graph

    A Hamiltonian cycle is a cycle that passes through all the

    vertices of the graph.

    A graph is called a Hamiltonian graph if it includes at least oneHamiltonian cycle.

    There are two stages in the Hamiltonian Cycle algorithm

    First, the graph is expanded to a complete graph to find thecycle easily. Then

    Manipulate this cycle by adding some edges and removingother edges so eventually a Hamiltonian cycle is formed thatincludes the edges that belong to the original graph

  • 8/13/2019 07e-HamiltoniannCycle

    3/18

    Dr. Ahmad R. Hadaegh

    A.R. Hadaegh Cali for nia State University San Marcos (CSUSM) Page 3

    HamiltonianCycle (graph G = (V, E))Set label of all edges to 0;K = 1;H = E; // set of edges

    GH= G; // original graph// Phase 1While GHcontains nonadjacent vertices v with u such thatdegH(v) + degH(u) >= |V| then

    H = H U {edges(vu)}

    GH= (V, H)Label(edge(vu)) = k++;

    // Phase 2If there exists a Hamiltonian cycle C

    k=max {label(edge(pq)) such that edge(pq) is in C}While (k > 0)

    C = a cycle due to a crossover with edge labeled by a number < k;k=max {label(edge(pq)) such that edge(pq) is in cycle C}

  • 8/13/2019 07e-HamiltoniannCycle

    4/18

    Dr. Ahmad R. Hadaegh

    A.R. Hadaegh Cali for nia State University San Marcos (CSUSM) Page 4

    Consider the following graph.

    We want to find the Hamiltonian cycle in this graph

    We start with phase 1 where we turn the graph into a completegraph with every vertex is connected to another vertex in thegraph

    d

    b

    e

    c

    a

    f

  • 8/13/2019 07e-HamiltoniannCycle

    5/18

    Dr. Ahmad R. Hadaegh

    A.R. Hadaegh Cali for nia State University San Marcos (CSUSM) Page 5

    We start with vertex a. Note that the total number of vertices in thegraph is |V| = 6

    The nonadjacent vertices to aare cand e

    accan be added becausedeg(a) + deg(c) = 3 + 3 = 6which is >= |V|

    After adding ac, the deg(a)becomes 4 and aeis also added becausedeg(a) + deg(e) = 4 + 2 = 6which is >=6

    d

    b

    e

    c

    a

    f

    d

    b

    e

    c

    a

    f

    1

    d

    b

    e

    c

    a

    f

    1

    2

  • 8/13/2019 07e-HamiltoniannCycle

    6/18

    Dr. Ahmad R. Hadaegh

    A.R. Hadaegh Cali for nia State University San Marcos (CSUSM) Page 6

    The nonadjacent vertices to bare d, e, and f

    bdcannot be added becausedeg(b) + deg(d) = 2 + 3= 5which is < 6

    becannot be added becausedeg(b) + deg(e) = 2 + 3= 5which is < 6

    bfcannot be added because

    deg(b) + deg(f) = 2 + 3= 5which is < 6

    d

    b

    e

    c

    a

    f

    1

    2

  • 8/13/2019 07e-HamiltoniannCycle

    7/18Dr. Ahmad R. HadaeghA.R. Hadaegh Cali for nia State University San Marcos (CSUSM) Page 7

    The nonadjacent vertices to cis d

    cdcan be added becausedeg(c) + deg(d) = 4 + 3= 7which is > 6

    d

    b

    e

    c

    a

    f

    1

    2d

    b

    e

    c

    a

    f

    1

    23

  • 8/13/2019 07e-HamiltoniannCycle

    8/18Dr. Ahmad R. HadaeghA.R. Hadaegh Cali for nia State University San Marcos (CSUSM) Page 8

    The nonadjacent vertices to dis b

    dbcan be added becausedeg(d) + deg(b) = 4 + 2= 6which is >= 6

    d

    b

    e

    c

    a

    f

    1

    23d

    b

    e

    c

    a

    f

    1

    234

  • 8/13/2019 07e-HamiltoniannCycle

    9/18Dr. Ahmad R. HadaeghA.R. Hadaegh Cali for nia State University San Marcos (CSUSM) Page 9

    The nonadjacent vertices to eare band f

    ebcan be added becausedeg(e) + deg(b) = 3 + 3= 6which is >= 6

    After adding eb, the deg(e)becomes 4 and efis also added becausedeg(e) + deg(f) = 4 + 3 = 7which is > 6

    d

    b

    e

    c

    a

    f

    1

    234

    d

    b

    e

    c

    a

    f

    1

    234

    5

    d

    b

    e

    c

    a

    f

    1

    234

    5

    6

  • 8/13/2019 07e-HamiltoniannCycle

    10/18Dr. Ahmad R. HadaeghA.R. Hadaegh Cali for nia State University San Marcos (CSUSM) Page 10

    The nonadjacent vertices to fis b

    fbcan be added becausedeg(f) + deg(b) = 4 + 4= 8which is > 6

    d

    b

    e

    c

    a

    f

    1

    234

    5

    6

    d

    b

    e

    c

    a

    f

    1

    234

    5

    67

  • 8/13/2019 07e-HamiltoniannCycle

    11/18Dr. Ahmad R. HadaeghA.R. Hadaegh Cali for nia State University San Marcos (CSUSM) Page 11

    Now the second phase starts.

    A cycle is created and Kbecomes the edge with the maximum value

    We order the vertices in the cycle such that the vertices attached toedge Kare on the extreme ends

    For the following cycle, the vertices are a, c, e, f , d, b

    K = ef

    Thus we order the vertices of the cycle as follows:f dbace

    d

    b

    e

    c

    a

    f

    1

    234

    5

    67

  • 8/13/2019 07e-HamiltoniannCycle

    12/18Dr. Ahmad R. HadaeghA.R. Hadaegh Cali for nia State University San Marcos (CSUSM) Page 12

    Now we find cross over edges and compare their value with thehighest value of current cycle.

    Two edge cross over each other if they each have a vertex that isthe end point of the current cycle

    The first cross over edges are fband de:f dbace

    This is not chosen because the weight of fbis 7 which is > 6

    d

    b

    e

    c

    a

    f

    1

    234

    5

    67

  • 8/13/2019 07e-HamiltoniannCycle

    13/18Dr. Ahmad R. HadaeghA.R. Hadaegh Cali for nia State University San Marcos (CSUSM) Page 13

    The next cross over edges are faand be:f dbace

    This is selected because behas weight 5 which is less that 6 Thus faand beare added and aband efare removed The edge with highest weight is now be= 5 The new cycle is:bdf ace

    d

    b

    e

    c

    a

    f

    1

    234 5

    67

    d

    b

    e

    c

    a

    f

    1

    234

    5

    67

  • 8/13/2019 07e-HamiltoniannCycle

    14/18Dr. Ahmad R. HadaeghA.R. Hadaegh Cali for nia State University San Marcos (CSUSM) Page 14

    We start to cross over the edges again in the new cyclebdf ace

    The first two edges are bfand de This combination is not chosen because the weight of bfis 7 which

    is bigger than 5, the maximum weight

    d

    b

    e

    c

    a

    f

    1

    234 5

    67

  • 8/13/2019 07e-HamiltoniannCycle

    15/18Dr. Ahmad R. HadaeghA.R. Hadaegh Cali for nia State University San Marcos (CSUSM) Page 15

    The next two edges are baand fe:bdf ace

    Again, this combination is not chosen because the weight of feis 6which is bigger than 5, the maximum weight

    d

    b

    e

    c

    a

    f

    1

    234 5

    67

  • 8/13/2019 07e-HamiltoniannCycle

    16/18Dr. Ahmad R. HadaeghA.R. Hadaegh Cali for nia State University San Marcos (CSUSM) Page 16

    The next two edges are bcand ae:bdf ace

    This combination is picked because the weight of aeis 2 which isless than 5, the maximum weight of the cycle

    Thus bcand aeare added and beand acare removed

    Now the maximum weigh of the new cycle is db = 4

    The new cycle isbceaf d

    d

    b

    e

    c

    a

    f

    1

    234

    5

    67

    d

    b

    e

    c

    a

    f

    1

    23

    45

    67

  • 8/13/2019 07e-HamiltoniannCycle

    17/18Dr. Ahmad R. HadaeghA.R. Hadaegh Cali for nia State University San Marcos (CSUSM) Page 17

    The next two edges are beand cd:bceaf d

    This combination is not picked because the weight of beis 5 whichis not less than 4

    The next two edges are baand ed:bceaf d

    This combination is picked because both edges belong to originalgraph and their weight is zero

    Thus baand edare added and bd and eaare removed

    The new cycle isabcedf

    d

    b

    e

    c

    a

    f

    1

    23

    45

    67

    d

    b

    e

    c

    a

    f

    1

    23

    45

    67

  • 8/13/2019 07e-HamiltoniannCycle

    18/18D Ah d R H d hA R Hadaegh Cali for nia State University San Marcos (CSUSM) Page 18

    Since the maximum weight of the new cycle is 0, it means all theedges belong to the original graph. Thus we are done.

    Thus the Hamiltonian cycle for our original graph is:

    d

    b

    e

    c

    a

    f

    d

    b

    e

    c

    a

    f

    1

    23

    45

    67


Recommended