AFAICS, this has not much to do with arithmetics. Adjacency lists just describe nodes of a graph or a tree. The numbers at the left are just nodes which are predecessors of nodes represented by the right-hand side integers in an oriented graph.

Update: If you want to represent the graph of this list:

1 2 1 5 1 7 2 6 2 8 3 1 3 2
Making some quite plausible assumptions on what exactly this list is supposed to represent, you might first draw a circle and name it 1 (write 1 in the middle of the circle) to represent the first node. This first node has three successors, 2, 5 and 7. So you just draw 3 other circles, with a 2, 5 and 7 in the middle, and draw an arrow from node 1 to nodes 2, 5 and 7. Then, from node 2 you draw two outbound arrows to the two new nodes, 6 and 8. Then you create node 3, and draw two arrows from it to existing nodes 1 and 2.

This is just one of the classical ways to represent graphs in a computer, there are some others.

In Perl, this graph could be implemented as an array of two-element arrays (([1, 2], [1, 5], [1, 7], ... [3, 2]), but, depending on what this graph is going to be used for, that might not be a very practical implementation to use. It could also be implemented as a hash of arrays: (1 => [2, 5, 7], 2 => [6, 8], 3 => [1, 2]), which might be more practical to use for some types of processing. For other types of calculations, you might want to reverse the representation and use the successor nodes as keys and predecessors (or lists of predecessors) as values or lists of values. It really depends on the data structure and the processing that needs to be done on it.

Je suis Charlie.

In reply to Re^2: Data type name required [not Perl exclusive question] by Laurent_R
in thread Data type name required [not Perl exclusive question] 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.