Notes From CS Undergrad Courses FSU
This project is maintained by awa03
Cycles
A[u][v]
is true if there is an edge from u to v, false otherwiseAdjacency matrix
A[u][v]
is true if there is an edge from u to vA[N][N]
- O(|V|^2) space
void Graph()::topsort{
for(int counter = 0; counter < NUM_VERT; counter++){
Vertex v - findNewVertexOfIndegreeZero();
if(v == NOT_A_VERTEX){
throw CycleFoundException()
}
v.topNum = counter;
for each Vertex w adjacent to v
w.indegree--;
}
}
void Graph::topsort(){
Queue<Vertex> q;
int counter = 0;
q.makeEmpty();
for each Vertex v
if( v.indegree == 0){
q.dequeue(v);
}
while(!q.isEmpty){
Vertex v = q.dequeue();
v.topNum ++counter;
for each Vertex w adjacent to v
if(--w.indegree == 0)
// Etc
}
}