darwinrlo / public

0 stars 0 forks source link

Debate #5

Open darwinrlo opened 4 years ago

darwinrlo commented 4 years ago

False dilemma

darwinrlo commented 4 years ago

We are given a directed graph and a vertex from the graph. We are to compute for each vertex other than the vertex we were given the shortest distance to it from the given vertex along any path through the graph. We will call the vertex we were given the origin vertex.

To start off, assign a key to each vertex. For the origin vertex, the key is assigned to be 0. All other vertices are assigned a key of INF (for positive infinity).

Next, create an instance of a set that we will use to store vertices for which the key is equal to the shortest distance along any path to it from the origin vertex. We'll call this set the result set.

Then insert all vertices into a heap. A heap element consists of a key and a value. In this case, the key is the key of the vertex, assigned previously. And the value is the vertex itself.

Now everything is set up and we do the following until the heap is empty:

Once the heap has been depleted, each vertex's key is now equal to the shortest distance along any path to it from the origin vertex.