Mark As Completed Discussion

Edge Lists

Now that we're all caught up on the fundamentals of graphs, let's talk implementation!

The first implementation strategy is called an edge list. An edge list is a list or array of all the edges in a graph. Edge lists are one of the easier representations of a graph.

In this implementation, the underlying data structure for keeping track of all the nodes and edges is a single list of pairs. Each pair represents a single edge and is comprised of the two unique IDs of the nodes involved. Each line/edge in the graph gets an entry in the edge list, and that single data structure then encodes all nodes and relationships.

Edge Lists

In the graph above, we have three nodes: 1, 2, and 3. Each edge is given an index and represents a reference from one node to another. There isn't any particular order to the edges as they appear in the edge list, but every edge must be represented. For this example, the edge list would look like the attached snippet:

1const edgeList = [
2	[1,2],
3	[2,3],
4	[3,1]
5];