laziness, impatience, and hubris | |
PerlMonks |
Algorithm Complexity and Determinism of Graph Moduleby ownlifeful (Beadle) |
on Jun 11, 2017 at 01:07 UTC ( [id://1192500]=perlquestion: print w/replies, xml ) | Need Help?? |
ownlifeful has asked for the wisdom of the Perl Monks concerning the following question:
Greetings, fellow Perl Monks, Please accept my sincere gratitude for being a wonderful Perl resource for everyone! With great humility and respect, I put forth this question before you: I am developing a new graph algorithm that utilizes the Graph module. The Graph module provides the $g->vertices() method. The results this method returns in a list context, are not deterministic. That is, for the same graph, when you call: my @vertices = $g->vertices();the vertices might be in different order. Since I rely on this method, my algorithm is also not deterministic. For a fixed given input, my algorithm produces the correct result, but the number of times it recurses varies wildly. I could just change it to: my @vertices = sort $g->vertices();everywhere, but that would kill the performance of the algorithm. Is there a better way? Also, I would appreciate any tips on computing the Big-O complexity of an algorithm implemented in Perl. Does one have to mentally unfurl every line of Perl down to C, while computing the complexity? I await your wise and erudite responses to enlighten me.
Back to
Seekers of Perl Wisdom
|
|