in reply to Data type name required [not Perl exclusive question]

Would you please explain for the terminology and arithmeticly challenged (to say nothing of a bit slow on the uptake in general; i.e., /me) how the the 3s (in rows 6 and 7) are the "parent interger(s)" of 1 and 2?


++$anecdote ne $data


Replies are listed 'Best First'.
Re^2: Data type name required [not Perl exclusive question]
by Laurent_R (Canon) on Mar 11, 2015 at 18:31 UTC
    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.