Question
Do a Depth-first search of the directed graph, starting at the node with value S (not case sensitive). List the starting and finishing times of
Do a Depth-first search of the directed graph, starting at the node with value S (not case sensitive). List the starting and finishing times of each Node, and the class of each Edge (tree edge, forward edge, back edge, cross edge). Make the starting time of the source node time 1. At many points in the search, you may have to choose which node to explore next. Here are the rules to do so:
1. If you have a choice among two or more unexplored Nodes to explore next, there are two cases:
a. If the values of all Edges are all integers, choose the Edge with the lowest value. If there is a tie, choose the Edge to the Node whose name comes first in lexicographic order. (All node names are unique.)
b. Otherwise, if the values of the Edges are not all integers (at least one general alphabetical character or non-positive integer), choose the Edge to the Node whose name comes first in lexicographic order.
2. If you have explored as far as possible from the starting node without exploring every node of the graph, continue from the Node whose name comes first lexicographically from among all unexplored Nodes.
Graph Class:
import java.util.*;
//Graph is a class whose objects represent graphs. public class Graph { ArrayList
}
public ArrayList
}
public void addNode(Node n) { nodeList.add(n);
}
public void addEdge(Edge e) { edgeList.add(e);
}
public String toString() { String s = "Graph g. "; if (nodeList.size() > 0) { for (Node n : nodeList) { // Print node info String t = " Node " + n.getName() + ", abbrev " + n.getAbbrev() + ", value " + n.getVal() + " "; s = s.concat(t); } s = s.concat(" "); } return s; } }
Node Class: public class Node {
String name; String val; // The value of the Node String abbrev; // The abbreviation for the Node ArrayList
DelivB Class (DelivB Need to be implemented) :
public class DelivB {
File inputFile; File outputFile; PrintWriter output; Graph g; public DelivB( File in, Graph gr ) { inputFile = in; g = gr; // Get output file name. String inputFileName = inputFile.toString(); String baseFileName = inputFileName.substring( 0, inputFileName.length()-4 ); // Strip off ".txt" String outputFileName = baseFileName.concat( "_out.txt" ); outputFile = new File( outputFileName ); if ( outputFile.exists() ) { // For re-tests outputFile.delete(); } try { output = new PrintWriter(outputFile); } catch (Exception x ) { System.err.format("Exception: %s%n", x); System.exit(0); } } }
Output: Here is sample output for one graph ABO.tct. val AAA BB CDDD E Alfa s S 99 fig Bravo 67 999 -42 3 x Charlie 4 yz 9 Delta 4e 3 22 Echo yes 33 U? ? x 2 2 3 The output for this file should be: Node Start Time Alpha 1 Bravo 2 Charlie 3 Delta Echo 5 End Time 10 9 8 7 6 Type Edge AAA-BB AAA-DDD AAA-EEE BB-AAA BB-BB BB-C BB-DDD BB-E C-BB C-DDD C-E DDD-AAA DDD-BB DDD-C DDD-E E-DDD E-E T h- H- HE TEEE THE BE TER The output for graphStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started