Priority First Traversal of a Graph


Set-Up:


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 */