I need to construct directed graph (at runtime) with cycles in Prolog and I am not sure know how to represent it. My requirement is that I need to get from one vertex to his neigbour in a constant time.
Is it possible to represent it as a tree, e.g.:
t(left_son,V,right_son)
but how to solve the cycles?
I can make a list of edges:
graph([a,b,c,d],[e(a,b),e(b,c),e(c,a),e(c,d)])
OR just
[a->[b],b->[c],c->[a,d],d->[]]
but how to avoid calling function 'member' on list while searching for neighbours, which cost linear time?
Thanks for your help