Sorry if this has been asked before but I wonder how to detect minimum number of nodes for given Hamiltonian Path for fixed endpoints. Lets say below is a Hamiltonian path from $1$ to $16$;
And if we keep endpoints ($1$ is start and 16 is end) and say one can only move from $2$ to $3$ we still end up with the same path. So my question is how to detect those unnecessary nodes to remove. Is there any source, subject or type of algorithm that I can use?
P.S. I want to solve this question without generating all other possible Hamiltonian Paths for $4\times 4$ grid. Thanks in advance.
A Hamiltonian path, by definition, must contain all nodes.
This is not too clear, but if you are asking for the shortest path from grid location $g_{ij}$ (row $i$ column $j$), then you can use a shortest path algorithm. If the shortest path (say from 1 to 16) must contain the edge 8-9, you can merge nodes 8 and 9 into a single node (that inherents its edges from the union of 8's and 9's edges) before running the shortest path algorithm. If what you have is a grid and not a graph, you can transform the grid into a graph, which is straight forward: each $g_{ij}$ is a node, and there is a directed edge from $g_{ij}$ to:
$g_{mj}$ where $m=i+1$ (the square above)
$g_{pj}$ where $p=i-1$ (the square below)
$g_{in}$ where $n=j-1$ (the square to the left)
$g_{ik}$ where $k=j+1$ (the square to the right)
Ensure that $k,m,p,n<=$ your grid's size otherwise don't create that edge.