hi,

i have a math problem that needs to be encoded in perl but i am having trouble figuring out the algorithm

Problem:

let N be a set of vertices (for our purposes let N={1,2,3,4} where numbers are vertex id's) Given any two vertices from N, label the edges so that no two adjacent edges are labelled the same and the number of labels does not exceed |N|-1.

Example:

Given a set of the above nodes: 1 2 3 4 The solution would be : b +-----------------+ | c | | +-----------+ + a | b a | 1-----2-----3-----4 | c | +-----------+ where a,b,c are edge labels and |{a,b,c}| = 3 = |N|-1
What would be an algorithm to efficiently identify and label these edges so that the end result is a table of pairs of vertices associated to edge labels:
1-2 => a 2-3 => b ...
This is quite trivial if a set of nodes is small but if i scale up the number i quickly lose myself.

Anyone encountered this problem before with an optimal solution?

PS: In real case scenario the number of nodes is close to 50


In reply to Graph labeling problem by baxy77bax

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.