Research Article

Hamiltonian Paths in Some Classes of Grid Graphs

Algorithm 3

The Hamiltonian path algorithm for 𝐹 -alphabet grid graphs.
  procedure 𝐹 _HamiltonianPath ( 𝐹 ( 𝑚 , 𝑛 ) , 𝑠 , 𝑡 )
1:  if   𝐹 can be stripped, where 𝐹 ( 𝑚 , 𝑛 ) is not odd sized and 𝑠 , 𝑡 𝑅 ( 2 𝑚 4 , 𝑛 )   then
2:   let 𝑆 be a strip of 𝐹
3:    𝑃 𝐹 𝑆 _HamiltonianPath ( 𝐹 𝑆 , 𝑠 , 𝑡 )
4:   /* 𝐹 𝑆 is a 𝐿 -alphabet grid graph 𝐿 ( 𝑚 , 𝑛 ) or a rectangular grid graph 𝑅 ( 2 𝑚 4 , 𝑛 )
    */
5:    𝐷 HamiltonianCycle ( 𝑆 )
6:   return MergeStrip ( 𝑃 , 𝐷 , 𝑠 , 𝑡 )
7:  else
8:   if   𝐹 can be stripped, where 𝐹 ( 𝑚 , 𝑛 ) is odd sized and 𝑠 , 𝑡 𝑅 ( 2 𝑚 4 , 𝑛 )   then
9:    let 𝑆 be a strip of 𝐹 , where 𝑆 is three rectangular grid graphs 𝑅 2 , 𝑅 3 and 𝑅 4
10:      𝑃 𝑅 _HamiltonianPath ( 𝑅 1 , 𝑠 , 𝑡 )
11:      𝑐 1 HamiltonianCycle ( 𝑅 3 )
12:      𝑐 2 HamiltonianCycle ( 𝑅 4 )
13:      𝐶 MergeCycles ( 𝑐 1 , 𝑐 2 )
14:      𝐷 HamiltonianCycle ( 𝑅 2 )
15:     return MergeStrip ( 𝑃 , 𝐷 , 𝐶 , 𝑠 , 𝑡 )
16:   else
17:  let 𝐹 be split to 𝑅 𝑝 and 𝐿 𝑞 (or 𝐿 𝑝 and 𝑅 𝑞 )
18:      𝑃 1 𝑅 _HamiltonianPath ( 𝑅 𝑝 , 𝑠 , 𝑝 )
19:      𝑃 2 𝐿 _HamiltonianPath ( 𝐿 𝑞 , 𝑞 , 𝑡 )
20:     return MergeSplit ( 𝑃 1 , 𝑃 2 , 𝑝 , 𝑞 )
21:   end  if
22:  end  if