📚 The CoCalc Library - books, templates and other resources
License: OTHER
Kernel: Python 3
Bipartite graphs
Code examples from Think Complexity, 2nd edition.
Copyright 2019 Allen Downey, MIT License
In [1]:
The following examples are from the NetworkX documentation on bipartite graphs
In [2]:
In [3]:
In [4]:
In [5]:
Exercise: Write a generator function called cross_edges
that takes a NetworkX Graph
object, G
, and a Python set
object, top
, that contains nodes.
It should compute another set
called bottom
that contains all nodes in G
that are not in top
.
Then it should yield all edges in G
that connect a node in top
to a node in bottom
.
In [6]:
In [7]:
In [8]:
In [9]:
In [10]:
In [11]:
In [12]:
In [13]:
In [14]:
In [15]:
Exercise: Write a function called is_bipartite
that takes a Graph
and a set of top nodes, and checks whether a graph is bipartite.
In [16]:
In [17]:
In [18]:
In [19]:
In [20]:
In [21]:
In [ ]: