Algorithm for checking connectivity of a lattice graph in Rn
Show older comments
Two points are adjacent if they have n-1 equal coordinates and 1 coordinate that differ by 1. For example, (1,4,3,0) in R^4 is adjacent to 8 points (0,4,3,0), (2,4,3,0), (1,3,3,0), (1,5,3,0), (1,4,2,0), (1,4,4,0), (1,4,3,-1) and (1,4,3,1). Two points are connected if there is a sequence of points between them, every two consecutive points are adjacent.
Suppose the input is a set of lattice points in R^n. What is a fast algorithm to check if they are connected? I only need to determine the connectivity (no need to find connected components); suppose all the points are contained in a given cube say [0,k]^n if this helps.
Thanks.
4 Comments
Assuming you have the coordinates as numeric vectors or arrays -
p1=[1,4,3,0] ;
n=numel(p1); %dimension of the space
fun = @(x) isequal(sort(abs(p1-x)),[zeros(1,n-1) 1]);
This assumes that coordinates are checked correspondingly (x to x, y to y, z to z ....)
p2=[0,4,3,0];
fun(p2)
p3=[2,4,3,0];
fun(p3)
p4=[1,3,3,0];
fun(p4)
%non-adjacent point
p5=[1,2,3,4];
fun(p5)
You can also modify the function handle for checking for any two pairs as well
Fun = @(in1,in2) isequal(sort(abs(in1-in2)),[zeros(1,n-1) 1]);
Haoran
on 9 Feb 2023
Dyuman Joshi
on 9 Feb 2023
How are the points stored? As numeric arrays corresponding to each dimension?
Please specify if otherwise.
Haoran
on 9 Feb 2023
Accepted Answer
More Answers (0)
Categories
Find more on Surface and Mesh Plots in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!