N
neiderer
If possible I'd like a recursive solution (Perl or C code would be
great
, or an algorithm) for the following input representing a network
of
nodes and links.
I know recursion in general is not the fastest solution but I'd like
to see
a solution using this approach to help me start thinking that way. If
not
appropriate a serial/procedural (maybe C) would work as well.
In this example the first node has "1" link to node "37". The 37th
node has
"4" links to nodes 2, 21, 13, 31. etc ...
I'd like to print out the entire path for each node. In this example
something like
# node 1 paths
37
37 2 ...
37 21 ...
37 13 ...
37 31 ...
..
..
..
It seems that this could be done using recursion.
If someone knows what I am after and could get me started I would be
indebted.
Thank you.
------------ sample input (excluding comments which begin with #
-------------------------------
# node 1
1,
37,
# node 2
1,
13,
# node 3
6,
30, 1, 34, 47, 48, 24,
3,
41, 47, 45
5,
48, 47, 16, 22, 10,
3,
18, 29, 9,
1,
15,
1,
24,
5,
32, 5, 12, 42, 19
2,
44, 15,
7,
6, 42, 45, 25, 20, 23, 53,
4,
45, 9, 23, 8,
1,
45,
4,
44, 34, 19, 29,
3,
22, 32, 35,
1,
4,
6,
28, 44, 34, 4, 33, 27,
3,
50, 49, 47,
7,
12, 45, 29, 40, 26, 44, 49,
5,
4, 5, 9, 47, 34,
7,
44, 39, 1, 47, 36, 19, 41,
4,
16, 37, 15, 41,
3,
37, 52, 50
1,
14,
2,
28, 44,
3,
16, 4, 40,
2,
46, 35,
6,
24, 33, 5, 51, 17, 8,
1,
51,
2,
44, 32,
6,
29, 7, 43, 3, 22, 37,
2,
12, 32,
3,
4, 34, 25,
2,
32, 8,
2,
13, 30,
4,
33, 51, 29, 47,
# node 37
2, 21, 13, 31,
4,
16, 21, 30, 48,
5,
30, 27, 39, 46, 11,
1,
34,
5,
51, 24, 32, 47, 41,
6,
4, 30, 24, 46, 21, 45
3,
11, 7, 40,
3,
5, 45, 8,
3,
6, 51, 52,
4,
11, 30, 29, 31,
6,
17, 7, 15, 48, 45, 47,
1,
5,
4,
45, 52, 49, 29,
4,
43, 31, 50, 40,
3,
1, 52, 31,
7,
24, 46, 15, 14, 34, 9, 8,
4,
10, 46, 8, 24
great
, or an algorithm) for the following input representing a network
of
nodes and links.
I know recursion in general is not the fastest solution but I'd like
to see
a solution using this approach to help me start thinking that way. If
not
appropriate a serial/procedural (maybe C) would work as well.
In this example the first node has "1" link to node "37". The 37th
node has
"4" links to nodes 2, 21, 13, 31. etc ...
I'd like to print out the entire path for each node. In this example
something like
# node 1 paths
37
37 2 ...
37 21 ...
37 13 ...
37 31 ...
..
..
..
It seems that this could be done using recursion.
If someone knows what I am after and could get me started I would be
indebted.
Thank you.
------------ sample input (excluding comments which begin with #
-------------------------------
# node 1
1,
37,
# node 2
1,
13,
# node 3
6,
30, 1, 34, 47, 48, 24,
3,
41, 47, 45
5,
48, 47, 16, 22, 10,
3,
18, 29, 9,
1,
15,
1,
24,
5,
32, 5, 12, 42, 19
2,
44, 15,
7,
6, 42, 45, 25, 20, 23, 53,
4,
45, 9, 23, 8,
1,
45,
4,
44, 34, 19, 29,
3,
22, 32, 35,
1,
4,
6,
28, 44, 34, 4, 33, 27,
3,
50, 49, 47,
7,
12, 45, 29, 40, 26, 44, 49,
5,
4, 5, 9, 47, 34,
7,
44, 39, 1, 47, 36, 19, 41,
4,
16, 37, 15, 41,
3,
37, 52, 50
1,
14,
2,
28, 44,
3,
16, 4, 40,
2,
46, 35,
6,
24, 33, 5, 51, 17, 8,
1,
51,
2,
44, 32,
6,
29, 7, 43, 3, 22, 37,
2,
12, 32,
3,
4, 34, 25,
2,
32, 8,
2,
13, 30,
4,
33, 51, 29, 47,
# node 37
2, 21, 13, 31,
4,
16, 21, 30, 48,
5,
30, 27, 39, 46, 11,
1,
34,
5,
51, 24, 32, 47, 41,
6,
4, 30, 24, 46, 21, 45
3,
11, 7, 40,
3,
5, 45, 8,
3,
6, 51, 52,
4,
11, 30, 29, 31,
6,
17, 7, 15, 48, 45, 47,
1,
5,
4,
45, 52, 49, 29,
4,
43, 31, 50, 40,
3,
1, 52, 31,
7,
24, 46, 15, 14, 34, 9, 8,
4,
10, 46, 8, 24