MCPcopy Create free account
hub / github.com/TheAlgorithms/Python / get_edges

Function get_edges

graphs/matching_min_vertex_cover.py:39–53  ·  view source on GitHub ↗

Return a set of couples that represents all of the edges. @input: graph (graph stored in an adjacency list where each vertex is represented as an integer) @example: >>> graph = {0: [1, 3], 1: [0, 3], 2: [0, 3], 3: [0, 1, 2]} >>> get_edges(graph) {(0, 1), (3, 1),

(graph: dict)

Source from the content-addressed store, hash-verified

37
38
39def get_edges(graph: dict) -> set:
40 """
41 Return a set of couples that represents all of the edges.
42 @input: graph (graph stored in an adjacency list where each vertex is
43 represented as an integer)
44 @example:
45 >>> graph = {0: [1, 3], 1: [0, 3], 2: [0, 3], 3: [0, 1, 2]}
46 >>> get_edges(graph)
47 {(0, 1), (3, 1), (0, 3), (2, 0), (3, 0), (2, 3), (1, 0), (3, 2), (1, 3)}
48 """
49 edges = set()
50 for from_node, to_nodes in graph.items():
51 for to_node in to_nodes:
52 edges.add((from_node, to_node))
53 return edges
54
55
56if __name__ == "__main__":

Callers 1

Calls 1

addMethod · 0.45

Tested by

no test coverage detected