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.


In reply to Algorithm Complexity and Determinism of Graph Module by ownlifeful

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.