Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6200817
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T04:26:15+00:00 2026-05-24T04:26:15+00:00

I have an undirected weighted graph and derive a new graph based on groups

  • 0

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).

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T04:26:15+00:00Added an answer on May 24, 2026 at 4:26 am

    If O(E + Ngroups^2) is an option where E is the number of edges in the given graph and Ngroups is the number of groups, you can do it as follows.

    You can create an adjacency matrix for the resulting graph. Then loop through all the edges in the given graph like

    for each edge u in Graph
        for v such that edge u->v exists
            let w be the weight of u->v
            A[group(u)][group(v)] := A[group(u)][group(v)] + w;
    

    You can rebuild the new graph from adjacency matrix if you wish.

    One possible optimization is to use a balanced tree to hold the edges starting in a particular node group instead of the whole adjacency matrix, this would lead to O(E*log(Ngroups)) time complexity.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have got an undirected weighted connected graph. If I select one vertex I
I have several nodes (undirected graph, bidirecional) ... Each two nodes have a distance...
If we have an (arbitrary) connected undirected graph G, whose edges have distinct weights,
I have a geometric undirected planar graph , that is a graph where each
I have an undirected graph with Vertex V and Edge E . I am
I have an undirected unweighted graph G = (V, E) and a randomly chosen
I have an n-partite (undirected) graph, given as an adjacency matrix, for instance this
I have a very, very large graph, and I want to find the shortest
Have a scenario with a client's new crm where they have suppliers and clients
Have an article model, each article has an author and publisher (both are tables).

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.