Example #1
0
def is_sparse(graph: Graph) -> bool:
    """
    Checks if |E| <= |V^2| / 2
    :param graph:
    :return:
    """
    return graph.size() <= (graph.order()**2 / 2)
Example #2
0
def is_simple(graph: Graph) -> bool:
    """
    A simple graph has no cycles
    :param graph:
    :return: whether or not the graph is simple
    """
    visited = {k: False for k in graph}
    rec_stack = [False] * graph.order()
    for v in graph:
        if not visited[v]:
            if check_for_cycles(graph, v, visited, rec_stack):
                return False
    return True
Example #3
0
 def test_order_and_size(self):
     json_graph = {"graph": {"A": ["B"], "B": []}}
     graph = Graph(input_graph=json.dumps(json_graph))
     self.assertEqual(2, graph.order())
     self.assertEqual(1, graph.size())