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

Function complete_graph

graphs/random_graph_generator.py:50–61  ·  view source on GitHub ↗

Generate a complete graph with vertices_number vertices. @input: vertices_number (number of vertices), directed (False if the graph is undirected, True otherwise) @example: >>> complete_graph(3) {0: [1, 2], 1: [0, 2], 2: [0, 1]}

(vertices_number: int)

Source from the content-addressed store, hash-verified

48
49
50def complete_graph(vertices_number: int) -> dict:
51 """
52 Generate a complete graph with vertices_number vertices.
53 @input: vertices_number (number of vertices),
54 directed (False if the graph is undirected, True otherwise)
55 @example:
56 >>> complete_graph(3)
57 {0: [1, 2], 1: [0, 2], 2: [0, 1]}
58 """
59 return {
60 i: [j for j in range(vertices_number) if i != j] for i in range(vertices_number)
61 }
62
63
64if __name__ == "__main__":

Callers 1

random_graphFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected