2014年10月15日星期三

Algorithms used in SNA

In last class we have learned the usage of shortest path in SNA(social network analysis), such as the calculation of “Closeness” or “Centrality”. To realize it, there are several famous algorithms, including “Dijkstra Algorithm”, “Floyd Algorithm” and “Prim Algorithm”. Following is a simple description of Dijkstra.

Let the node at which we are starting be called the initial node. Let the distance of node Y be the distance from the initial node to Y. Dijkstra algorithm will assign some initial distance values and will try to improve them step by step.
1. Assign to every node a tentative distance value: set it to zero for our initial node and to infinity for all other nodes.
2. Mark all nodes unvisited. Set the initial node as current. Create a set of the unvisited nodes called the unvisited set consisting of all the nodes.
3. For the current node, consider all of its unvisited neighbors and calculate their tentative distances. Compare the newly calculated tentative distance to the current assigned value and assign the smaller one.
4. When we are considering all of the neighbors of the current node, mark the current node as visited and remove it from the unvisited set. A visited node will never be checked again.
5. If the destination node has been marked visited (when planning a route between two specific nodes) or if the smallest tentative distance among the nodes in the unvisited set is infinity (when planning a complete traversal; occurs when there is no connection between the initial node and remaining unvisited nodes), then stop. The algorithm has finished.
6. Select the unvisited node that is marked with the smallest tentative distance, and set it as the new "current node" then go back to step 3.

It is also widely used in many other places. For example, in Google Maps, we often try to find the path to a certain building or some city, and the app will suggest us a way which is the shortest(shortest in distance or time). Using the same thinking, we get the shortest way to the next crossing or neighbor city, then repeat this process until finally get the whole path to destination.


Pathway from Hong Kong to Beijing by Google Map

Likely, in computer networks, routing strategies can help a router find the path to send packets to the next router, of which the widely used protocol-OSPF(Open Shortest Path First Interior Gateway Protocol) is just based on Dijkstra Algorithm.


2 条评论:

  1. Hi Tianyu,
    Thanks for sharing a shortest path algorithm. I learned how to calculate the shortest path between two nodes from your step-by-step description. Algorithms with respect to these kinds of detailed aspects are rarely contained by our course lectures. So I think you are very meticulous.

    回复删除
  2. Floyd algorithm is more easier to understand but need more time to complete its calculation. How to choose these two algorithms in a real case?

    回复删除