Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re: Finding connected components in a graph.

by SuicideJunkie (Vicar)
on Oct 02, 2012 at 18:15 UTC ( #996888=note: print w/ replies, xml ) Need Help??


in reply to Finding connected components in a graph.

I haven't read YAML before, (Data::Dumper is nice and perl-y), so I'm partly guessing at the structure here.

@subgraphs looks like a list of the connected components. Pick one element of the array, and you're looking at one subgraph.

The number of connected components is just 0+@subgraphs.


Comment on Re: Finding connected components in a graph.
Replies are listed 'Best First'.
Re^2: Finding connected components in a graph.
by zing (Beadle) on Oct 02, 2012 at 18:25 UTC
    Hi there, As per your suggestion I added these two lines, but as you can see in the output section the results are totally invalid.
    print "First connected component == $subgraphs[1]\n"; print "Number of connected components== $#subgraphs\n";
    -----OUTPUT----------
    5 ----connected components--------------- - - c - b - a - - e - d First connected component == ARRAY(0x9a8e308) Number of connected components== 1

      Yes. The subgraph is an array reference. Dig in! foreach my element (@{ $subgraphs[0] }) {...}

      As expected, the last index in your two element array is 1. The other index is 0. As I wrote, you want to print 0+@subgraphs, or more explicitly, scalar(@subgraphs).

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://996888]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (8)
As of 2015-07-29 08:34 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (261 votes), past polls