I’ll be breaking each part into a few steps, with some background information. If you’d prefer to just look at the code, here is the link to the gist.
Background: What is a graph?
A graph is an abstract data type used to model a set of connections. For example, say Bob follows Sarah and Lou on Twitter. Sarah follows Lin. Lou follows Lin and Mark. We can represent these connections using a graph.
Read more at HackerNoon