Custom Search
|
Re: [QUIZ] Perl 'Medium' Quiz: Graph Connected Components (#2006-12-29)
Date: December 31, 2006
In-reply-to:
<200612292141.15282.shlomif-ik1l9ssToec+JF/nGntIXQ@xxxxxxxxxxxxxxxx> 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
|