ownlifeful has asked for the wisdom of the Perl Monks concerning the following question:
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.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Algorithm Complexity and Determinism of Graph Module
by Laurent_R (Canon) on Jun 11, 2017 at 08:51 UTC | |
|
Re: Algorithm Complexity and Determinism of Graph Module
by LanX (Saint) on Jun 11, 2017 at 05:07 UTC | |
|
Re: Algorithm Complexity and Determinism of Graph Module
by Anonymous Monk on Jun 11, 2017 at 01:34 UTC | |
|
Re: Algorithm Complexity and Determinism of Graph Module
by ownlifeful (Beadle) on Jun 11, 2017 at 11:03 UTC | |
by Discipulus (Canon) on Jun 11, 2017 at 22:29 UTC | |
by ownlifeful (Beadle) on Jun 12, 2017 at 13:21 UTC |