Monday, March 14, 2011

Algorithms Analysis -> Preparing the class -> The Dijsktra Algorithm

It's a habit I've been procrastinating for a while but from now on I'm reviewing the class materials in advanced as there are so many concepts that won't stick at the first try, and I'm my grades lately aren't as good as I'd like them to be.

We'll be reviewing the Dijkstra algorithm ( I studied itfor the first time a couple of years ago, so my knowledge of it is kind of rusty at the moment)

  • What is it used for? It finds the shortest path in a graph from a starting point (called source) to all other nodes.

  • What does the algorithm do?

  1. Creates a table where the distance from the source (say, node a) to any other node is set to infinity. Why? To make sure that any path found will be shorter than the initial value stored in the table.

  2. The distances are updated so  we write in the table the real distances from the source to any other node that has only one edge separating them from the source.

  3. The algorithm moves now to the node with the shortest distance from (a)  within the nodes described in step 2 (say node c).

  4. Being in that new node, we examine what nodes are the closest and calculate their distance from node (a).

  5. Compare the results in step 4 with those in step 2.

  6. When all paths starting from node c have been visited we check it so it's not visited again.

This pattern continues 'till all nodes have been visited. There's a little more to it but it's 3:00 am and I'm starting to feel sleepy and dizzy.

No comments:

Post a Comment