A common task in computer science is to check if two nodes in the network are connected  if there is a path between those two nodes. While such a task is rarely, if ever, needed for social science research questions, we use the problem as an example of how to think and approach the network through algorithms. There are two common strategies to identify if two nodes are connected: depthfirst search and breadthfirst search. The breadthfirst search strategy starts from either of the two nodes (for simplicity, we call this A) and searches for the other node (called X) from these nodes. The algorithm first checks all the neighbours of the initial node A and examines if any of the neighbours is node X (see Figure 4.7) If not, the algorithm continues the analysis through all the neighbours of A, looking at one node at a time. That is, it searches through nodes B, D and E. First, the algorithm analyses all neighbours of A's first neighbour (node B), then all neighbours of A's second neighbour (D) and so on. This is continued until node X is found or all connected nodes have been analysed and X is not found. Programming this algorithm requires additional tools beyond variables, loops and control structures. This problem is returned to later in Code Example 5.6.
