Priority First Traversal of a Graph
Set-Up:
- Each vertex of the graph has a status variable
which has one of three values: {WAITING, READY, VISITED}
- A priority queue called readyPQ has been created and initialized to an
empty state.
Procedure PriorityFirstTraversal
{
Set the status of each vertex to WAITING ;
For each node V in the graph
If status(V) is WAITING
Then VisitComponentOf(V) ;
}
Iterative Version of Procedure VisitComponentOf
Procedure VisitComponentOf(vertex V)
{ /* Begin Procedure VisitComponentOf */
Place V in readyPQ ;
While ( readyPQ is not empty )
{ /* begin while-loop */
Let X be the highest priority element of readyPQ;
Remove X from readyPQ;
Process X ;
Set status(X) = VISITED;
For each N adjacent to X with status(N) = WAITING
{
Set status(N) to READY;
Place N in readyPQ;
}
} /* end while-loop */
} /* End Procedure VisitComponentOf */