Showing posts with label edges. Show all posts
Showing posts with label edges. Show all posts

Sunday, June 3, 2018

How do you create an undirected graph in Python?

An undirected graph in discrete mathematical formulation is a structure in which some pairs of objects are in some sense related (Wikipedia). A line with two end points is a graph element with two nodes connected by an edge stretching between the two points.

Here are some examples of graphs:

 The above from Wikipedia. Graph with  6 nodes and 7 edges.
This one with 6 nodes and 8 edges.

In Python you can construct a dictionary that associates nodes with edges as shown here in this schematic.


In this graph 5 edges are associated with 6 edges and it can be represented by this dictionary object,

A is connected to B and C while A,B,D and E connects to C.

Review this post after the above:
http://hodentekhelp.blogspot.com/2018/06/how-do-you-construct-python-dictionary.html