In a “dense” graph, I am trying to construct a Hamiltonian cycle using Palmer’s Algorithm. However, I need more explanation for this algorithm because it does not work with me when I implement it. It seems that there is an unclear part in Wikipedia’s explanation.
I would be thankful if someone explains it more clearly or give me some links to read.
Here’s the algorithm statement:
Palmer (1997) describes the following simple algorithm for constructing a Hamiltonian cycle in a graph meeting Ore’s condition.
Arrange the vertices arbitrarily into a cycle, ignoring adjacencies in the graph.
While the cycle contains two consecutive verticesviandvi + 1that are not adjacent in the graph, perform the following two steps:
Search for an index
jsuch that the four verticesvi,vi + 1,vj, andvj + 1are all distinct and such that the graph contains edges fromvitovj + 1and fromvjtovi + 1Reverse the part of the cycle between
vi + 1andvj(inclusive).
To be more specific, I do not get the part where they say:
“Arrange the vertices arbitrarily into a cycle”
in this case, is this right to do: 0,1,2,3,4,0
and what do they mean by: “Reverse the part of the cycle”?
Indeed, wikipedia’s description of the algorithm
is¹was wrong. Palmer’s own description isYou need a pair of crossing chords, i.e. you need edges
That way, by reversing the part from
v_{i+1}tov_j(inclusive), you move the vertexv_j– adjacent tov_iin the graph – next tov_iin your cycle, and the vertexv_{i+1}– adjacent tov_{j+1}in the graph – is moved next tov_{j+1}in the cycle. Thus we obtain two new pairs of neighbours in the cycle that are adjacent in the graph,(v_i, v_j)and(v_{i+1}, v_{j+1}), and possibly destroy one pair of cycle-neighbours that are adjacent in the graph,(v_j, v_{j+1}). The number of pairs of cycle-neighbours that are adjacent in the graph increases by 1 or by two each step, so the algorithm terminates.With the wrong indexing of wikipedia, moving
v_jnext tov_iandv_{i+1}next tov_{j+1}need not generate a new pair of cycle-neighbours that are adjacent in the graph, thus the algorithm need not terminate.So let’s play it through for your example
arranging it as
1426351initially (no adjacent neighbours).The first pair of cycle-neighbours not adjacent in the graph is
(1,4) = (v_1,v_2). Scan for an indexj > 2such thatv_jis adjacent tov_1andv_{j+1}tov_2, the first such occurrence isj = 3. Now reverse the part4...2in the cycle (in this case, there’s no vertex between 4 and 2), giving the next cyclewith two pairs of adjacent neighours (
(1,2)and(4,6)). The first indexiwithv_inot adjacent tov_{i+1}is 2. Scan for the firstj > 3such thatv_jis adjacent tov_2 = 2andv_{j+1}adjacent tov_3 = 4. That givesj = 5. Now the part betweenv_3andv_5(inclusive), giving the next cycleOnce more,
v_3 = 3is not adjacent tov_4 = 6, soi = 3,j = 5, reversing yieldsNow the only bad pair is
(v_6,v_1) = (5,1). The smallestj > 1such thatv_jis adjacent tov_6 = 5andv_{j+1}tov_1 = 1isj = 2. Now reverse the part fromv_1tov_2yieldingwhich is a Hamiltonian cycle.
¹ I’ll fix it in a moment.