graph algorithm - How to find same edges of two paths? -
a path represented vector, containing node id. edge in path has direction.
given 2 paths, example : <1,6,11,7,2,5 ...> , <3, 4, 8, 2, 7,3, 1,6...>, here <1,6> same edge. edges successive, times not. it's better put flag between these edges. example, (1,2) * (5,7,9) * (6,11,12), same edge 1->2, 5->7,7->9, 6->11, 11->12, there no edges 2 5 or 9 6. put '*' or other symbol flag.
is there has ideas? appreciate it.
assuming each node has 1 incoming , 1 outcoming edge. call p1 first path of length n , p2 second path of length m. can turn p2 hashmap startedge -> endedge
(e.g <3,4,5>
become [3->4, 4->5]
).
then each element of p1, number i
, compare p1(i+1)
hashmap(key= p1(i))
. if hashmap doesn't have key or has different value, don't have common edge, otherwise do.
(if have multiple edges 1 node, values of hashmap can sets of ints, , check whether p1(i+1)
contained within hashmap(key=p1(i))
).
Comments
Post a Comment