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 5966023
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T19:43:56+00:00 2026-05-22T19:43:56+00:00

I am using igraph (via python) for graph clustering. I have a tree (a

  • 0

I am using igraph (via python) for graph clustering.

I have a tree (a minimal spanning tree of a geometric graph) with weighted-edges, and want to calculate weight times
the smaller number of vertices of the two components if the edge is
deleted:

def sep(graph, e):
    h = copy(graph)
    w = h.es[e]['weight']
    h.delete_edges(e)
    return w * min(h.components().sizes())

# 'graph' is the tree I am dealing with
ss = [sep(graph,x) for x in range(len(graph.es))]

My questiones are:

  1. Is this a known (and named) property in graph theory? If so, what is
    it?

  2. My piece of code is very inefficient if I calculate this for all the
    edges, as shown above. If the graph becomes 50000 edges and vertices,
    memory consumption becomes huge. Do you have some suggestions for
    optimizing?

  • 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-22T19:43:57+00:00Added an answer on May 22, 2026 at 7:43 pm

    Elaborating a bit more on yurib’s answer, I would do something like this (also posted on the igraph mailing list):

    I will use two attributes, one for the vertices and one for the edges. The edge attribute is simple, it will be called cut_value and it is either None or contains the value you are looking for. Initially, all these values are Nones. We will call edges with cut_value=None unprocessed and edges where “cut_value is not None“` processed.

    The vertex attribute will be called cut_size, and it will be valid only for vertices for which there exists exactly one unprocessed incident edge. Since you have a tree, you will always have at least one such vertex unless all the edges are processed (where you can terminate the algorithm). Initially, cut_size will be 1 for all the vertices (but remember, they are valid only for vertices with exactly one unprocessed incident edge).

    We will also have a list deg that contains the number of unprocessed edges incident on a given node. Initially all the edges are unprocessed, hence this list contains the degrees of the vertices.

    So far we have this:

    n, m = graph.vcount(), graph.ecount()
    cut_values = [None] * m
    cut_sizes = [1] * n
    deg = graph.degree()
    

    We will always process vertices with exactly one incident unprocessed edge. Initially, we put these in a queue:

    from collections import deque
    q = deque(v for v, d in enumerate(deg) if d == 1)
    

    Then we process the vertices in the queue one by one as follows, until the queue becomes empty:

    1. First, we remove a vertex v from the queue and find its only incident edge that is unprocessed. Let this edge be denoted by e

    2. The cut_value of e is the weight of e multiplied by min(cut_size[v], n - cut_size[v]).

    3. Let the other endpoint of e be denoted by u. Since e now became processed, the number of unprocessed edges incident on u decreased by one, so we have to decrease deg[u] by 1. If deg[u] became 1, we put u in the queue. We also increase its cut_size by one because v is now part of the part of the graph that will be separated when we later remove the last edge incident on u.

    In Python, this should look like the following code (untested):

    weights = graph.es["weight"]
    while q:
        # Step 1
        v = q.popleft()
        neis = [e for e in graph.incident(v) if cut_value[e] is None]
        if len(neis) != 1:
            raise ValueError("this should not have happened")
        e = neis[0]
    
        # Step 2
        cut_values[e] = weights[e] * min(cut_sizes[v], n - cut_sizes[v])
    
        # Step 3
        endpoints = graph.es[e].tuple
        u = endpoints[1] if endpoints[0] == v else endpoints[0]
        deg[u] -= 1
        if deg[u] == 1:
            q.append(u)
        cut_sizes[u] += 1
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

It is very straight-forward to plot a tree using igraph in R library(igraph) plot(graph.tree(20,
I have the following problem. I'm using the C library igraph (http://igraph.sourceforge.net/) in a
I'm using a dictionary to represent a graph in my Python program. I'm using
Using online interfaces to a version control system is a nice way to have
Using PyObjC , you can use Python to write Cocoa applications for OS X.
Using TortoiseSVN against VisualSVN I delete a source file that I should not have
Using the variables extension, I want to change the background color of a cell
Using Core Data. Let's say we have models for Team and Player. Assume: -Each
Using a site like StackOverflow as an example: I have a table of users,
Using just python, is it possible to possible to use a USB flash drive

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.