

Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Information on two important graph algorithms: topological sort and shortest path. The first algorithm constructs an ordering of vertices in a directed acyclic graph such that there is no path from a vertex with a larger index to a vertex with a smaller index. The second algorithm finds the shortest weighted path from a single distinguished vertex to every other vertex in a graph. Pseudocode for both algorithms and discusses their complexities.
Typology: Study notes
1 / 2
This page cannot be seen from the preview
Don't miss anything!


4/12/2004 CS216, Spring 2004 1
4/12/2004 CS216, Spring 2004 2
4/12/2004 CS216, Spring 2004 3
4/12/2004 CS216, Spring 2004 4
void Graph::topsort(){ Queue q(NUM_VERTICES); int counter = 0; Vertex v, w;
q.makeEmpty(); for each vertex v if (v.indegree == 0) q.enqueue(v); while (!q.isEmpty()){ v = q.dequeue(); v.topologicalNum = ++counter; for each w adjacent to v if (--w.indegree == 0) q.enqueue(w); } if (counter != NUM_VERTICES) throw CycleFound(); }
4/12/2004 CS216, Spring 2004 5
i
4/12/2004 CS216, Spring 2004 6
4/12/2004 CS216, Spring 2004 7
4/12/2004 CS216, Spring 2004 8
4/12/2004 CS216, Spring 2004 9
4/12/2004 CS216, Spring 2004 10
4/12/2004 CS216, Spring 2004 11