# Check Specific Connections within Graph

Say you have the skeleton of a graph:

nodeset= PolyhedronData["Icosahedron", "SkeletonRules"]


and you've an arbitrary list of some fraction of those nodes, say given = {1,4,10}, which you want to turn into the list of all nodes connected directly to those given (along with the number of given each is connected to).

With,

connCheckTool[node1_, node2_] := Count[nodeset, (node1 -> node2)] + Count[nodeset,(node2 -> node1)]


The following function achieves this:

DeleteCases[
DeleteCases[
Transpose@{Range[20],
Total /@
Table[connCheckTool[i, given[[z]]], {i, 1, 120, 1}, {z,
1, Length@given}]} /. {x_Integer, 0} -> delete, delete], {x_, y_} /;
MemberQ[given, x] == True];


However, the inner connCheckTool is not very efficient, especially with larger graphs.

Can anyone think of a way to accomplish this in a better way?

I suspect it will involve the AdjacencyMatrix of the original, whole graph, as opposed to the list-search mechanism, but can't quite get it...

• Checked AdjacencyList in the docs? And NeighborhoodGraph and SubGraph? – kglr Apr 10 '14 at 10:30
• I had an apparently undue paranoia of using Graph objects more than needed. Thank you for correcting that. – Ghersic Apr 11 '14 at 2:58

Tally[Join @@ (AdjacencyList[Graph[nodeset], #] & /@ given)]