I met some problem when I use JSON for implementing adjacency list. First thing was, I cant use a 'integer value' as id in the id:value pair . so I rethink about my problem and approached in another way and I implemented the adjacency list as below(as a list of list).
Current solution
The representation of each node of a graph by its cartesian co-ordinates is really a low-level representation. At the algorithm level, we need to associate a single unique number with each vertex; for example, you can map:
- vertex 0 ---> (100, 200)
- vertex 1 ---> (45, 78)
- vertex 2 ---> (198, 213)
I made a list for all vertexes:
eg: nodes = [[100,200],[45,78],[198,213]]
in which nodes[1] gives the coordinates for vertex 1.
And adjacency list is of the form of a list of list.
adj_list = [[1,2,3], [0, 4, 5] ]
adj_list[1] gives you list of nodes adjacent to node1. and so on..
This means: adjacent to (directly connected to) vertex 0, you have vertices 1, 2, 3.
Adjacent to vertex 1, you have vertices 0, 4, 5 ...
I found this solution is more suitable to my problem. Thanks to Dave and Jiri for their reply.