I think this question of OP might be more appropriate for a site with more graph theory people. Anyhow, the following seems to be a reasonable strategy: Given the graph G
, try to construct an auxiliary graph auxG
, with directed edges and weights, so that the available function FindShortestPath
on auxG
solves the problem that OP is asking on G
. This will be useful if auxG
can be constructed reasonably quickly and is of a similar size as G
.
To see what I mean: If one moves right-right-right-right-... then one extends the combined neighborhood by 3 with each hop. If one moves right-up-right-up-... then on average one extends the not by 3+3 for each right-up-combination, but only by 5. So we could give weight 3 to each existing edge, and add diagonal edges with weight 5. In this case, auxG
would have the same vertices as G
, but more edges.
Because of the boundary, which is important in this problem, we have to do something similar near the boundary. I will not describe this in words and just drop the code:
(* original grid graph *)
n=10;
G=GridGraph[{n,n},VertexLabels->Automatic];
coords=Round[VertexCoordinates/.AbsoluteOptions[G,VertexCoordinates]];
(* neighborhood computations *)
nbh0[vertex_,dist_:1]:=VertexList[NeighborhoodGraph[G,vertex,dist]];
nbh0[vertex_,dist_,distmax_]:=Select[nbh0[vertex,dist],(Norm[coords[[vertex]]-coords[[#]],Infinity]<=distmax)&];
nbh[vertex_,x___]:=DeleteCases[nbh0[vertex,x],vertex];
sizenbh[vertices_]:=Length[DeleteDuplicates[Flatten[Map[nbh0,vertices]]]];
(* construct auxG *)
aux[from_,to_]:=sizenbh[FindShortestPath[G,from,to]]-sizenbh[{from}];
aux[from_]:=Map[{DirectedEdge[from,#],aux[from,#]}&,nbh[from,2,1]];
{auxedges,auxweights}=Transpose[Flatten[Map[aux,VertexList[G]],1]];
auxG=Graph[auxedges,EdgeWeight->auxweights,VertexLabels->Automatic];
(* find path *)
findPath[from_,to_]:=Flatten[Map[FindShortestPath[G,#[[1]],#[[2]]]&,
Partition[FindShortestPath[auxG,from,to],2,1]]]//.{a___,b_,b_,c___}:>{a,b,c};
I stress that the construction of auxG
is currently ad-hoc, I have not verified that it really generates the paths that OP wants.
Here is G
:

Here is auxG
. It has directed edges with weights. Away from the boundary, the weights are $3$ for horizontal or vertical hop, and $5$ for diagonal hop. Near the boundary it is a bit more complicated:

Examples: Corner to opposite corner:
p1 = findPath[1,100]
(* {1,2,3,4,5,6,7,8,9,10,20,30,40,50,60,70,80,90,100} *)
Let us compare with the diagonal path:
p2 = {1,11,12,22,23,33,34,44,45,55,56,66,67,77,78,88,89,99,100};
They have equal neighborhood size:
Map[sizenbh,{p1,p2}]
(* {36,36} *)
The first example of OP is essentially
p3 = findPath[1,33]
(* {1,11,12,22,23,33} *)
which is the path OP has given. Finally, consider two paths from the left boundary to the right boundary:
p4=findPath[3,93]
(* {3,2,1,11,21,31,41,51,61,71,81,91,92,93} *)
p5=findPath[4,94]
(* {4,14,24,34,44,54,64,74,84,94} *)
Note that p4
walks along the boundary, p5
does not.
Map[sizenbh,{p4,p5}]
(* {26,30} *)
This shows that p4
is indeed better than walking horizontally, which would have neighborhood size 30
. And p5
is as good as walking along the boundary, which also has neighborhood size 30
.
Again, I do not claim that this always produces the paths that OP wants, but it seems to go in the right direction. It is based on calling FindShortestPath
once (on auxG
) so should be reasonably efficient.