In a Graph application, I obtain ConnectedComponents of unordered edges. Then I systematically form ordered pairs of each component vertices with vertices of the others to obtain candidateBridges per component.
I’m wondering if my algorithm can be accomplished in a more functional way, or perhaps more efficiently with built-in functions?
Here’s an example:
In[]:=
connectedComponents={{a,b,c,d},{e,f,g},{h,i}};(*INPUT*)​​cCcount=Length[connectedComponents];​​candidateBridges=Table[{},cCcount];​​Do[​​componentCount=Length[connectedComponents[[n]]];​​indices=If[n≠#,#,Nothing]&/@Range[cCcount];​​Do[​​AppendTo[candidateBridges[[n]],({connectedComponents[[n,m]],#}&/@connectedComponents[[#]])&/@indices];​​{},​​{m,1,componentCount}​​];​​candidateBridges[[n]]=Flatten[candidateBridges[[n]],2];​​{},​​{n,1,cCcount}​​];​​Print[candidateBridges//Column];​​(*OUTPUT*)
{{a,e},{a,f},{a,g},{a,h},{a,i},{b,e},{b,f},{b,g},{b,h},{b,i},{c,e},{c,f},{c,g},{c,h},{c,i},{d,e},{d,f},{d,g},{d,h},{d,i}}
{{e,a},{e,b},{e,c},{e,d},{e,h},{e,i},{f,a},{f,b},{f,c},{f,d},{f,h},{f,i},{g,a},{g,b},{g,c},{g,d},{g,h},{g,i}}
{{h,a},{h,b},{h,c},{h,d},{h,e},{h,f},{h,g},{i,a},{i,b},{i,c},{i,d},{i,e},{i,f},{i,g}}