Good graph traversal algorithm

前端 未结 4 1720
终归单人心
终归单人心 2020-12-16 18:21

Abstract problem : I have a graph of about 250,000 nodes and the average connectivity is around 10. Finding a node\'s connections is a long process (10 seconds lets say). Sa

4条回答
  •  醉话见心
    2020-12-16 18:43

    Although you say that getting a friend list takes a lot of time (10 seconds or more), a variant of good-old Dijkstra's algorithm just might work:

    1. Get any node.
    2. Get a connection from any node you already loaded.
    3. If the other end hasn't been loaded yet, add the node to the graph.
    4. Go to step 2.

    The trick is to select the connection you load in step 2 in a smart way. A few short remarks about this:

    • You should somehow prevent the same connection to be loaded twice or more often. Selecting a random connection and discard it if it's been loaded already is very inefficient if you're after all connections.
    • If you want to load all connections eventually, load all connections of a node at the same time.

    In order to really say something about efficiency, please provide more details about datastructure.

提交回复
热议问题