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

Function initialize_unweighted_undirected_graph

graphs/basic_graphs.py:21–32  ·  view source on GitHub ↗
(
    node_count: int, edge_count: int
)

Source from the content-addressed store, hash-verified

19
20
21def initialize_unweighted_undirected_graph(
22 node_count: int, edge_count: int
23) -> dict[int, list[int]]:
24 graph: dict[int, list[int]] = {}
25 for i in range(node_count):
26 graph[i + 1] = []
27
28 for e in range(edge_count):
29 x, y = (int(i) for i in _input(f"Edge {e + 1}: <node1> <node2> "))
30 graph[x].append(y)
31 graph[y].append(x)
32 return graph
33
34
35def initialize_weighted_undirected_graph(

Callers

nothing calls this directly

Calls 2

_inputFunction · 0.85
appendMethod · 0.45

Tested by

no test coverage detected