Reordering Adjacency Lists

39 views
Skip to first unread message

Adrian Neumann

unread,
Sep 18, 2012, 7:24:58 AM9/18/12
to networkx...@googlegroups.com
Hi,

is there a way to order the adjacency list of a graph such that for
example a DFS visits nodes with a higher label first? It appears that
the adjacency list is stored as an unordered dictionary.

Greets,

Adrian

Aric Hagberg

unread,
Sep 19, 2012, 3:53:45 PM9/19/12
to networkx...@googlegroups.com
The adjacency structure is based on Python dictionaries so there is no
ordering of the nodes by default. You could modify the depth first
algorithms to order the nodes during traversal.
Here is an example of how to do that to visit the nodes in sorted
order (nodes must be sortable).
https://gist.github.com/3751844
Aric
Reply all
Reply to author
Forward
0 new messages