Question: JAVA Question Standard DFS ( V , E ; s 0 ) Input: , G = ( V , E ) a digraph and s
JAVA Question
Standard DFS ;
Input: a digraph and inV
The vertices in are colored white, gray or black
so is uhite.
Output Application dependent
Color as gray, and VISIT
for each adjacent to do
PREVISIT
if is white then
Standard DFS ; Recursive call
Color black, and POSTVISIT
Standard DFS is a recursive program contain three "macros":
Think of macros as simple subroutines that executes a few basic instructions
so it has complexity For instance, it might contain a single assignment
statement
clock
to set the finish time of node Thus, until we specify these macros, the
Standard DFS is not fully specified. The vertices of are initially all uhite,
but each time we call the Standard DFS some of their color changes. The
color transitions may be correlated with the macros:
white VISIT gray POSTVISIT black.
It is useful to view PREVISIT as "visiting the edge
How do we ensure that the precondition of Standard DFS that vertices of
must be colored whitegrayblack This precondition can be fulfilled if we
assume that the Standard DFS is called by another routine called the DFS
Driver:
Note that there are Driver macros:
To implement any of the DFSbased algorithms, it remains for us to specify
these macros. By default, a macro is assumed to be NOOP ie
empty unless we specify it In this exercise, we ask you to specify these
macros.
For example, if we want to assign discoverytime and finishtime to
nodes, the DRIVERINIT macro must to initialize two arrays
and dotsnassuming We also need a clock
variable to be initialized to or Notioe that all these are global
variables that recursive DFS can access.
Let DFS Pair refer to the pair of algorithms DFS Driver, Standard DFS
In the following, we want you to specify the macros of the DFS Pair in in
order to solve various problems. You only have to explicitly program those
macros that are not NOOPs. We call this macro programming of the DFS
pair.
a Please program the macros of the DFS Pair so that reproduce the be
havior of the Full DFS in Slides
Specifically, the Full DFS outputs the array representing the DFS
forest, and also the two arrays and for the discovery time
and finish time.
b Please program the macros of the DFS Pair in order to implement Tarjan's
Topological Sort Algorithm.
Specifically: Tarjan's algorithm produces a sequence dots, repre
senting the topological sort.
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
