Two-Hop Neighbours

Returns the 2-hop network of a node `n`.

This algorithm will return the two hop neighbours of each node in the graph. If the user provides a node ID, then it will only return the two hop neighbours of that node.


  • node (String) : The node ID to start with. If not specified, then this is run for all nodes.
  • output (String) : The path where the output will be saved. If not specified, defaults to /tmp/twoHopNeighbour


  1. In the first step the node messages all its neighbours, saying that it is asking for a two-hop analysis.

  2. Each vertex, starting from a triangle count of zero, looks at the lists of ID requests it has received, it then finds all of its neighbours and replies to the node in the form (response, neighbour, me).

  3. The requester compiles these into a list of results


As this sends alot of messages between nodes, running this for the entire graph with a large number of iterations may cause you to run out of memory. Therefore it is most optimal to run with a select node at a time. The number of iterations makes a difference to ensure all messages have been read.


  • First Hop ID (Long): ID of the first hop
  • Second Hop ID(Long): ID of the second hop
  • Third Hop ID (Long): ID of the third hop

2hop-network example