I have an undirected weighted graph and derive a new graph based on groups of existing nodes: each group becomes a node in the new graph, connected to others based on the total weight of the edges between the original nodes.
In the current data structure, each node has a list of its neighbors and weights, and the algorithm takes each group / each node in group / each edge in node, and sums up the weights in order to determine the edges of the new graph.
This algorithm works fine, but it's slow - is there a way to avoid the 3-level iterations?
Keeping a single list of edges is an option, but when the new graph is built, the new list of edges would have to be scanned at each step to see if that edge already exists (and to increment its weight).
O(E + Ngroups^2)
an option? How many groups are there? – unkulunkulu