Re: [QUIZ] Perl 'Medium' Quiz: Graph Connected Components (#2006-12-29)
"Michael C. Toren" <[email protected]> Sun, 31 Dec 2006 18:19:38 -0500
| Newsgroups | gmane.comp.lang.perl.qotw.discuss |
|---|---|
| Message-ID | <[email protected]> |
On Fri, Dec 29, 2006 at 09:41:15PM +0200, Shlomi Fish wrote:
> A--B--F D--C
> | /
> |/
> E
[ ..]
> You should implement a function called "connected" that will receive
> such an input and return its connected components, where a connected
> component is such that for every two nodes in it, there's a path from
> one to the other. So for the graph above the function will return:
>
> [
> [[$A,$B],[$B,$E],[$B,$F],[$F,$E]],
> [[$D,$C]],
> ]
Would it perhaps make more sense for the "connected" function to return a
list of nodes, rather than links, for which there is some path connecting
them? For example:
[
[ $A, $B, $F, $E ],
[ $D, $C ]
]
Thanks,
-mct